Yep,

You don't directly see it, but if i have understood older posts
correctly, sBackground has a reference to a context that was used when
it was created. This context is the activity-context that holds on to
the activity that originally was used when creating sBackground.

So, via via, sBackground is referring to the activity that was used
when sBackground was created. A configuration change destroys the
activity and creates a brand-new one...

If all it OK, you should only have on activity (the new one) and the
old one should be a candidate for garbage collection. But sBackground
is (indirectly) still referencing the old activity and it will not be
garbage collected.

Don't cache the drawable (in a static). But you can cache the bitmap
from that drawable:

sBackgroundBitmap =
((BitmapDrawable)getDrawable(R.drawable.large_bitmap)).getBitmap();



On Apr 10, 4:51 am, Michael Rueger <[email protected]> wrote:
> On 4/10/2010 10:38 AM, NoraBora wrote:
>
> > I understand sBackground has a reference to TextView, and the TextView
> > has a reference to Activity.
> > I know when a device is rotated, Activity is destroyed and created
> > again.
>
> > but I think when a new Activity is created, sBackground setCallback a
> > new TextView and the TextView has reference to the new Activity.
>
> > Then the old TextView and the old Activity is not refered by
> > sBackground so they can be garbage-collected.
> > which means this code has no memory-leaks.
>
> You are basically right, it is not a leak in the "classical" C-style sense.
>
> But...
> An Activity is also destroyed when you navigate back in the activity
> stack within your own application and the above code (or rather the
> static variable) would hold on to the activity needlessly.
>
> Michael

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to