views:

457

answers:

2

Is there any way to stop the garbage collector for some time?

+1  A: 

I guess you are willing to avoid getting lagged by the gc. If this is the case, your question is similar to this one.

Basically you can't stop the gc but you can force a call using System.gc().

Macarse
ok thanks alot, i knew it was possible to start it but i hoped it would also be possible to stop it (and then only run it when lags wouldnt be noticed)
Sponge
+1  A: 

The best way of not be lagged by the GC is to avoid the need to collect garbage all the time. You could for example reuse objects instead of nulling them and creating new ones. This quite same pattern as androids CursorAdapter is doing when reusing the View's, it just reused a view to represent new data. The drawback of this that you have to do it manually and program in a very precise way. Also you'll get a better memory handling and a performance boost.

Moss