I am removing the view from FrameLayout and reinserting it back again at different z-level, but this is leading to increase in "Private Dirty" memory. I assume, FrameLayout is just referring to the reference of the view I am adding. I am not sure why removing and re-inserting the same view again leads in inflating memory. Am I missing something?
Asked
Active
Viewed 137 times
0
-
Because it creates new view objects every time when you inflate. However the old views should automatically be cleared by GC when they are unreachable. – waqaslam Jan 09 '15 at 13:27
-
oh! you mean to say on every insert it would create new object and clone it.. is it? But then when I remove it, it should be cleaned by GC right? Keeping a reference for that view should not matter. If this is how it works, then there is something wrong in my code, and I have to dig it out.... Correct me if I am wrong.. – Sumedh Shantaram Jan 09 '15 at 13:32
-
If you clean references to the old views then they should be cleaned automatically but there's no guarantee when or what time they will be cleaned because it depends on GC. If the device runs on low memory then there might be a possibility that GC will be engaged quite actively and freeing up RAM. Review your logcat and see if you find GC related logs there too. – waqaslam Jan 09 '15 at 13:54
-
Does your activity crash due to OutOfMemory exception after any number of view inflation? If not, then you dont need to bother with this issue at all because then GC is working efficiently to free up memory. – waqaslam Jan 09 '15 at 23:13
-
Unfortunately it crashes, with out of memory exception. What I am doing is, on any external event (lock, minize, home), in onResume removing a view and adding it back again, perhaps I am leaking memory somewhere else. – Sumedh Shantaram Jan 12 '15 at 10:08
-
The view I am removing and reinserting is the GLSurfaceView on which I am drawing some OpenGL graphics. Memory dump indicates that there is a drastic increase in "other dev" section, which could be graphics textures, etc. explained here http://stackoverflow.com/questions/13245489/detailed-explanation-for-profile-from-adb-shell-dumpsys-meminfo-my-app-name, I think I need to free buffers allocated for openGL drawings, which is taking the toll here.. – Sumedh Shantaram Jan 12 '15 at 13:04
-
Sorry, no clue for OpenGL :( – waqaslam Jan 12 '15 at 13:06