标签:mssql quick down wsm success move isp cts center
|
楼主
发表于:
2015-09-25 09:30:49
这几天发现Volley的网络请求有内存溢出现象。(检测工具是MAT,LeakCanary)
感觉现象很常见,也许大家还没发现,或着已经解决。
此代码大家可以直接COPY就能运行。 LeakCanary显示:StringRequest的参数,有个匿名内部类监听一直持有HeapTestActivity 这个对象,导致无法释放。 MAT显示如下图: |
||
|
#1
得分:0
回复于:
2015-09-30 15:47:36
整个项目中用一个RequestQueue ,可以弄成单例模式。官网上有写,然后创建RequestQueue 的时候用Application的context。If your application makes constant use of the network, it‘s probably most efficient to set up a single instance of RequestQueue that will last the lifetime of your app. You can achieve this in various ways. The recommended approach is to implement a singleton class that encapsulates RequestQueue and other Volley functionality. Another approach is to subclass Application and set up the RequestQueue in Application.onCreate(). But this approach is discouraged; a static singleton can provide the same functionality in a more modular way.
A key concept is that the RequestQueue must be instantiated with the Application context, not an Activity context. This ensures that the RequestQueue will last for the lifetime of your app, instead of being recreated every time the activity is recreated (for example, when the user rotates the device). |
|
#2
得分:0
回复于:
2015-10-02 19:53:37
楼上正角,必须只持有一个RequestQueue
|
|
#3
得分:40
回复于:
2015-10-04 15:34:12
使用单例模式,下面是google官方给的example
|
||
Volley内存溢出, Volley使用者快来看看,也许你也会遇到-CSDN论坛-CSDN.NET-中国最大的IT技术社区
标签:mssql quick down wsm success move isp cts center
原文地址:http://www.cnblogs.com/Jxiaobai/p/6617673.html