Symbian
Symbian OS Library

FAQ-0540 My app crashes periodically with an Alloc 0 error on the debug emulator. What can I do?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: JNI
Created: 11/17/2000 Modified: 06/25/2001
Number: FAQ-0540
Platform: Not Applicable

Question:
I am writing JNI code to run on the debug emulator. I find my app crashes periodically with an Alloc 0 error indicating a memory leak. I can't see why this is happening.

Answer:
This is very likely caused by a mismatch between Symbian OS's and Java's memory management policies. If, say, you make a call to a method like GetStringUTFChars which allocates memory on the Java side, then deallocate it with ReleaseStringUTFChars, the deallocation may not occur when you expect as this is done asynchronously by the Java garbage collector. So encapsulating these calls between __UHEAP_MARK and __UHEAP_MARKEND calls will likely provoke an Alloc 0 panic.

The way out of this problem is to avoid the use of the MARK/MARKEND macros in JNI code. Note that it is not self-evident to the user which methods in the function table accessed by JNIEnv* may and may not result in an allocation of memory during their execution, i.e. this is an implementation-dependent detail. So it is safest just not to use the MARK/MARKEND macros in any JNI code.