[mono-android] Possible GC Bug?

Piotr Kryger piotr.kryger at gmail.com
Tue Mar 29 04:49:10 EDT 2011


I found some strange behaviour, when I call GC.Collect() directly -
sometimes it causes my application to quit.
I'm able to reproduce this (on emulator and on device - both Android 2.2)
following these steps:
 - run attached project
 - click "Run A" button, activity A is launched
 - press back to return to main launcher activity
 - click "Run A" once again and application quits

I don't get any exception, adb log looks like this:

> 03-29 08:37:16.010: INFO/TEST(331): create Activity1
> 03-29 08:37:16.260: INFO/TEST(331): resumed Activity1
> 03-29 08:37:16.340: WARN/InputManagerService(59): Got RemoteException
> sending setActive(false) notification to pid 322 uid 10042
> 03-29 08:37:21.150: INFO/ActivityManager(59): Starting activity: Intent {
> cmp=GcTest.GcTest/gctest.A }
> 03-29 08:37:21.310: INFO/monodroid(331): Activating instance of type
> GcTest.A
> 03-29 08:37:21.310: INFO/monodroid(331): signature
> 03-29 08:37:21.390: INFO/TEST(331): create A
> 03-29 08:37:21.459: INFO/TEST(331): collect
> 03-29 08:37:21.610: DEBUG/dalvikvm(331): GC_EXPLICIT freed 7690 objects /
> 380920 bytes in 63ms
> 03-29 08:37:21.640: INFO/TEST(331): collect finished
> 03-29 08:37:21.640: INFO/TEST(331): collect
> 03-29 08:37:21.670: INFO/TEST(331): collect finished
> 03-29 08:37:22.010: INFO/ActivityManager(59): Displayed activity
> GcTest.GcTest/gctest.A: 764 ms (total 764 ms)
> 03-29 08:37:23.280: WARN/KeyCharacterMap(331): No keyboard for id 0
> 03-29 08:37:23.280: WARN/KeyCharacterMap(331): Using default keymap:
> /system/usr/keychars/qwerty.kcm.bin
> 03-29 08:37:23.389: INFO/TEST(331): resumed Activity1
> 03-29 08:37:23.690: INFO/TEST(331): destroy A
> 03-29 08:37:23.829: INFO/TEST(331): collect
> 03-29 08:37:23.890: DEBUG/dalvikvm(331): GC_EXPLICIT freed 291 objects /
> 10872 bytes in 53ms
> 03-29 08:37:23.900: INFO/TEST(331): collect finished
> 03-29 08:37:23.910: INFO/TEST(331): collect
> 03-29 08:37:23.970: DEBUG/dalvikvm(331): GC_EXPLICIT freed 20 objects / 656
> bytes in 54ms
> 03-29 08:37:23.990: INFO/TEST(331): collect finished
> 03-29 08:37:24.700: INFO/ActivityManager(59): Starting activity: Intent {
> cmp=GcTest.GcTest/gctest.A }
> 03-29 08:37:24.779: INFO/monodroid(331): Activating instance of type
> GcTest.A
> 03-29 08:37:24.779: INFO/monodroid(331): signature
> 03-29 08:37:24.790: INFO/TEST(331): create A
> 03-29 08:37:24.800: INFO/TEST(331): collect
> 03-29 08:37:24.870: DEBUG/dalvikvm(331): GC_EXPLICIT freed 170 objects /
> 13664 bytes in 57ms
> 03-29 08:37:24.890: INFO/TEST(331): collect finished
> 03-29 08:37:24.910: DEBUG/Zygote(33): Process 331 terminated by signal (11)
> 03-29 08:37:24.920: INFO/ActivityManager(59): Process GcTest.GcTest (pid
> 331) has died.
> 03-29 08:37:24.940: INFO/WindowManager(59): WIN DEATH: Window{43fbeed8
> GcTest.GcTest/gctest.Activity1 paused=false}
>

Is this a bug or have I missed something?

Thanks,
Piotr

2011/3/18 Jonathan Pryor <jpryor at novell.com>

> 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
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110329/285a9fa9/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GcTest.zip
Type: application/zip
Size: 12345 bytes
Desc: not available
Url : http://lists.ximian.com/mailman/private/monodroid/attachments/20110329/285a9fa9/attachment-0001.zip 


More information about the Monodroid mailing list