I am doing what http://www.droidnova.com/2d-tutorial-series-part-ii,772.html has done but I am making new instances of SurfaceView that are causing Out of memory exception.
I have done profiling with the help of Eclipse MAT and it showed me that SurfaceView has never died. although I am killing the thread that is running onDraw and also the activity but still it remains present in memory.
any idea?
You should probably remove SurfaceViews that you aren’t using from the view hierarchy by calling
ViewGroup#removeView(surfaceView)on their parents. TheSurfaceView, and objects in general, can’t be garbage collected until no other objects are referencing them.You might also consider reusing SurfaceViews instead of creating new ones.