問題描述
如何清理視圖對象? (How to clean view object?)
I'm developing an application where I have one activity and many view subclasses. When I need to change the view I'm calling a loading screen (which is another view class) and load the new view on a separate thread (using runnable) and when it's ready I'm setting the view with SetContentView
function.
Now the problem that I face is that I run out of memory. Because every view has it's own list of objects that it loads.
Now my question is, how do I free memory, so I won't run into the out of memory
exception?
P.S. I have tried nulling the old view and recycling all the bitmaps that it has and then calling for System.gc()
though no luck so far.
參考解法
方法 1:
Do a thread.interrupt () when the view is not in focus
方法 2:
Try using intents to display the views in different classes.
方法 3:
was thinking you could try to split the views into different activity classes.then you can start an activity with startActivityforResult(intent) and when you aee done with the view,just call finish().it will get remove the resources from memory.
(by AngryChicken、Jack Wachira、Jack Wachira、Jack Wachira)