Java – android map, markup, and memory leaks

android map, markup, and memory leaks… here is a solution to the problem.

android map, markup, and memory leaks

I’m reading the android documentation
http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html
I came across this phrase:

Any objects obtained from the GoogleMap is associated with the view. It’s important to not hold on to objects (e.g. Marker) beyond the view’s life. Otherwise it will cause a memory leak as the view cannot be released.

I

don’t fully understand, I’m not sure if it works for me, but I just wanted to check: this only works if the fragment is destroyed and the main view is still there, right? My map fragment is the only element in the XML of that layout, so I assume that when the user leaves, the markup object (and everything else) is destroyed. Am I right, or is it just the opposite?

Solution

If you look at a fragment lifecycle You can see that the view may be corrupted, while the fragment remains. It can also recreate the View before the fragment is destroyed. It just means that you should clean up and create all tags in the onCreateView. and onDestroyView callback. If you use these callbacks for tag operations, you should be fine.

Related Problems and Solutions