[mono-android] Possible GC Bug?
Jonathan Pryor
jpryor at novell.com
Fri Mar 18 12:56:34 EDT 2011
On Mar 18, 2011, at 12:43 PM, Aaron Knabb wrote:
> However, if I am creating and disposing of a large bitmap every time my activity is recreated (say in an ImageView), I run out of memory before long.
The problem -- which is present on every GC system -- is that Mono's GC doesn't know how big the Dalvik-allocated bitmap is (just as .NET's GC doesn't know that you just called Marshal.AllocHGlobal() to allocate 4GB of memory...). Furthermore, Mono's GC _can't_ know how big the Dalvik-allocated bitmap is, and even if you knew how much memory it took GC.AddMemoryPressure() isn't supported.
Thus, in this (and similar) cases you need to help the GC out, as you know things the GC doesn't, and thus the GC.Collect() call is appropriate.
- Jon
More information about the Monodroid
mailing list