Soccercheng

2009年2月11日 星期三

Android Developers Blog: Avoiding memory leaks

Android Developers Blog: Avoiding memory leaks

I have a question about the 2nd example, it says “When the screen orientation changes the system will, by default, destroy the current activity and create a new one while preserving its state”.

After onCreate was first called,

Drawable --> View1 ---> Context1
<--

After orientation changes, the onCreate will be called again

Drawable <-- View1 ---> Context1

Drawable --> View2 ---> Context2
<--

So, View1 reference count will be 0 and it will be garbage collected, after that, Context1 will be garbage collected too.

So, there won’t be no memory leak!!??