My question is regarding a memory leak I am facing (android development), but not able to find the root cause for the same.
I have two classes - A and B. Class A has an object of B - objectB. Class B has an instance variable mTempBitmap of type Bitmap. In class A, I create a bitmap object aBitmapObject & initialize - objectB.mTempBitmap = aBitmapObject. In class B, I set mTempBitmap to null in API onDraw().
Now, what happens is, on each key press, objectB's mTempBitmap is updated, and then objectB.onDraw gets called. But, if we press keys too fast, sometimes onDraw() will not get called.
In this situation, I can see a memory leak. If I take a heap dump and analyse with memory analyzer MAT tool, I find 50-60 objects of bitmap, which were not expected.
So, I am not clear with the definition of memory leak in Java, though I read a couple of SO posts on it.
Could the memory leak occuring in the above situation be because of onDraw() not getting called, and objectB.mTempBitmap not being updated to null ?? (afaik, even if objectB.mTempBitmap was not made null, later mTempBitmap will point to another bitmap, so there should be no problem of memory leak.) Is it because somewhere copies of bitmap get created and they leak out ?? When we initialise objectB.mTempBitmap = aBitmap, are there any copies of bitmap created, or just another reference gets attached to the same bitmap ?? (afaik, just another refernce to same bitmap, no new bitmap copy created)
If anybody has idea, help !