I have an android app that goes back and forth between a couple of screens organized as fragments of an activity that uses a viewPager to make scrolling possible.
When moving too much within these screens the app crashes with an
JNI ERROR (app bug): local reference table overflow (max=512)
here is the stacktrace:
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] JNI ERROR (app bug): local reference table overflow (max=512)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] local reference table dump:
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] Last 10 entries (of 512):
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 511: 0x144abc00 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 510: 0x144abbc0 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 509: 0x144abb80 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 508: 0x144abb40 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 507: 0x144abb00 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 506: 0x144abac0 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 505: 0x144aba80 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 504: 0x144aba40 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 503: 0x144aba00 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 502: 0x144ab9c0 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] Summary:
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 511 of long[] (6 elements) (511 unique instances)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 1 of java.lang.Thread
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127]
03-23 13:25:56.781 3493-3573/? D/StatusBarManagerService: manageDisableList userId=0 what=0x0 pkg=Window{5a171b1 u0 d0 Starting de.everskill.everskill.debug}
03-23 13:25:56.791 3035-3035/? D/libEGL: eglInitialize EGLDisplay = 0x7fff60dac8
03-23 13:25:56.791 1976-1976/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-23 13:25:56.791 1976-1976/? A/DEBUG: Build fingerprint: 'samsung/zerofltexx/zeroflte:6.0.1/MMB29K/G920FXXU5DQA7:user/release-keys'
03-23 13:25:56.791 1976-1976/? A/DEBUG: Revision: '11'
03-23 13:25:56.791 1976-1976/? A/DEBUG: ABI: 'arm64'
03-23 13:25:56.791 1976-1976/? A/DEBUG: pid: 8120, tid: 8699, name: pool-2-thread-1 >>> de.everskill.everskill.debug <<<
03-23 13:25:56.791 1976-1976/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
03-23 13:25:56.811 1976-1976/? A/DEBUG: Abort message: 'art/runtime/indirect_reference_table.cc:127] JNI ERROR (app bug): local reference table overflow (max=512)'
03-23 13:25:56.811 1976-1976/? A/DEBUG: x0 0000000000000000 x1 00000000000021fb x2 0000000000000006 x3 0000000000000000
03-23 13:25:56.811 1976-1976/? A/DEBUG: x4 0000000000000000 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
03-23 13:25:56.811 1976-1976/? A/DEBUG: x8 0000000000000083 x9 0000000000016240 x10 000000000057d960 x11 000000000057daa0
03-23 13:25:56.811 1976-1976/? A/DEBUG: x12 0000000000000000 x13 0000007f960f5000 x14 0000000000000000 x15 0000007f960e7000
03-23 13:25:56.811 1976-1976/? A/DEBUG: x16 0000007f960e7568 x17 0000007f9607a338 x18 0000000000000000 x19 0000007f59dff500
03-23 13:25:56.811 1976-1976/? A/DEBUG: x20 0000007f59dff440 x21 0000000000000011 x22 0000000000000006 x23 0000007f64056240
03-23 13:25:56.811 1976-1976/? A/DEBUG: x24 0000007f9236cbc0 x25 0000007f78ac5200 x26 0000007f92475bc0 x27 0000000000000001
03-23 13:25:56.811 1976-1976/? A/DEBUG: x28 0000007f64056100 x29 0000007f59dfe8b0 x30 0000007f96077ad4
03-23 13:25:56.811 1976-1976/? A/DEBUG: sp 0000007f59dfe8b0 pc 0000007f9607a340 pstate 0000000020000000
03-23 13:25:56.821 1976-1976/? A/DEBUG: backtrace:
03-23 13:25:56.821 1976-1976/? A/DEBUG: #00 pc 0000000000069340 /system/lib64/libc.so (tgkill+8)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #01 pc 0000000000066ad0 /system/lib64/libc.so (pthread_kill+68)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #02 pc 0000000000023910 /system/lib64/libc.so (raise+28)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #03 pc 000000000001e240 /system/lib64/libc.so (abort+60)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #04 pc 0000000000430e38 /system/lib64/libart.so (_ZN3art7Runtime5AbortEv+304)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #05 pc 00000000001373a4 /system/lib64/libart.so (_ZN3art10LogMessageD2Ev+3136)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #06 pc 0000000000272f88 /system/lib64/libart.so (_ZN3art22IndirectReferenceTable3AddEjPNS_6mirror6ObjectE+372)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #07 pc 000000000035bff0 /system/lib64/libart.so (_ZN3art3JNI21GetObjectArrayElementEP7_JNIEnvP13_jobjectArrayi+472)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #08 pc 0000000000156ee0 /system/lib64/libart.so (_ZN3art8CheckJNI21GetObjectArrayElementEP7_JNIEnvP13_jobjectArrayi+524)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #09 pc 0000000000052ef4 /data/app/de.everskill.everskill.debug-3/lib/arm64/librealm-jni.so (Java_io_realm_internal_TableQuery_nativeBatchUpdateQueries+616)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #10 pc 00000000018e6d40 /data/app/de.everskill.everskill.debug-3/oat/arm64/base.odex (offset 0xddf000) (long[] io.realm.internal.TableQuery.nativeBatchUpdateQueries(long, long[], long[][], long[][], boolean[][])+244)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #11 pc 0000000001903578 /data/app/de.everskill.everskill.debug-3/oat/arm64/base.odex (offset 0xddf000) (void io.realm.internal.async.QueryUpdateTask.run()+588)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #12 pc 0000000001900748 /data/app/de.everskill.everskill.debug-3/oat/arm64/base.odex (offset 0xddf000) (void io.realm.internal.async.BgPriorityRunnable.run()+140)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #13 pc 0000000003492ec0 /system/framework/arm64/boot.oat (offset 0x2f48000)
What I got from googleing is that I am basically not cleaning up the memory I allocate and since I never leave the activity it is not done by the garbage collector automatically.
So I need to manullay release the allocated memory. But can you hint me towards anything on what to look for?
What kind of elements do allocate memory in this JNI Table?
And what is the JNI table?
How do I free memory in the table?
Thanks a lot guys!
Best
TobHo
Related
I have table in my application and I'm Running my app on Huawei y9 and this error pops up after a 30 sec and force close my application. I link my other question that I put the code of my table btw Im ussing implementation "androidx.room:room-runtime:2.3.0" and
annotationProcessor "androidx.room:room-compiler:2.3.0" but I don't think this casing the error.
my Error :
2022-03-05 20:41:45.893 29390-29425/com.example.myapplication A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10 in tid 29425 (HeapTaskDaemon), pid 29390 (e.myapplication)
2022-03-05 20:41:46.093 29837-29837/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2022-03-05 20:41:46.094 29837-29837/? A/DEBUG: Build fingerprint: 'HUAWEI/JKM-LX1/HWJKM-H:9/HUAWEIJKM-LX1/9.1.0.309C185:user/release-keys'
2022-03-05 20:41:46.094 29837-29837/? A/DEBUG: Revision: '0'
2022-03-05 20:41:46.094 29837-29837/? A/DEBUG: ABI: 'arm64'
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: Happend: 'Sat Mar 5 20:41:46 2022
'
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: SYSVMTYPE: Art
APPVMTYPE: Art
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: pid: 29390, tid: 29425, name: HeapTaskDaemon >>> com.example.myapplication <<<
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: Cause: null pointer dereference
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x0 0000007cd5ef6f00 x1 0000007cb6eede48 x2 0000000000000008 x3 0000000000000400
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x4 0000000017e08744 x5 0000000013489974 x6 0000000017e1fa50 x7 0000000017e1fa50
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x8 0000000000000000 x9 fbafe48ae0791bf6 x10 0000000042c00000 x11 0000000000000008
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x12 000000000000000b x13 17e053d000000000 x14 0000007cd5ec0d50 x15 00000cefaa754cdb
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x16 0000007cd5b95ec0 x17 0000007d5909fdf0 x18 0000007cd5abea50 x19 0000007cb6eede48
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x20 0000000070c0d868 x21 0000000000000008 x22 00000000714d2528 x23 00000000714d10b0
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x24 0000000000000028 x25 00000000000023c8 x26 0000000000001478 x27 0000007cb6eef588
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x28 00000000714d10c8 x29 0000007cb6eede30
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: sp 0000007cb6eeddc0 lr 0000007cd570e08c pc 0000007cd570e068
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: backtrace:
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #00 pc 00000000001d7068 /system/lib64/libart.so (_ZN3art6mirror6Object15VisitReferencesILb1ELNS_17VerifyObjectFlagsE0ELNS_17ReadBarrierOptionE1ENS_2gc9collector17ConcurrentCopying16RefFieldsVisitorES8_EEvRKT2_RKT3_+2504)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #01 pc 00000000001c9594 /system/lib64/libart.so (art::gc::collector::ConcurrentCopying::ImmuneSpaceScanObjVisitor::Callback(art::mirror::Object*, void*)+68)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #02 pc 00000000001bb220 /system/lib64/libart.so (art::gc::accounting::ModUnionTableReferenceCache::VisitObjects(void (*)(art::mirror::Object*, void*), void*)+224)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #03 pc 00000000001c6770 /system/lib64/libart.so (art::gc::collector::ConcurrentCopying::MarkingPhase()+244)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #04 pc 00000000001c51b8 /system/lib64/libart.so (art::gc::collector::ConcurrentCopying::RunPhases()+1176)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #05 pc 00000000001db930 /system/lib64/libart.so (art::gc::collector::GarbageCollector::Run(art::gc::GcCause, bool)+320)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #06 pc 0000000000201860 /system/lib64/libart.so (art::gc::Heap::CollectGarbageInternal(art::gc::collector::GcType, art::gc::GcCause, bool)+3404)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #07 pc 00000000001ff654 /system/lib64/libart.so (art::gc::Heap::DoPendingCollectorTransition()+108)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #08 pc 00000000002185c0 /system/lib64/libart.so (art::gc::Heap::CollectorTransitionTask::Run(art::Thread*)+40)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #09 pc 000000000023ab48 /system/lib64/libart.so (art::gc::TaskProcessor::RunAllTasks(art::Thread*)+68)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #10 pc 0000000000092a6c /system/framework/arm64/boot-core-libart.oat (offset 0x90000) (dalvik.system.VMRuntime.clampGrowthLimit [DEDUPED]+124)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #11 pc 0000000000580588 /system/lib64/libart.so (art_quick_invoke_stub+584)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #12 pc 00000000000d8608 /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #13 pc 000000000028cec8 /system/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+344)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #14 pc 0000000000286ed0 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #15 pc 0000000000547bf8 /system/lib64/libart.so (MterpInvokeVirtual+588)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #16 pc 0000000000572c94 /system/lib64/libart.so (ExecuteMterpImpl+14228)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #17 pc 00000000000bbe7e /system/framework/boot-core-libart.vdex (java.lang.Daemons$HeapTaskDaemon.runInternal+38)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #18 pc 0000000000260bd4 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.4179671085+488)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #19 pc 00000000002666c8 /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #20 pc 0000000000286eb4 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #21 pc 0000000000547bf8 /system/lib64/libart.so (MterpInvokeVirtual+588)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #22 pc 0000000000572c94 /system/lib64/libart.so (ExecuteMterpImpl+14228)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #23 pc 00000000000bb9b4 /system/framework/boot-core-libart.vdex (java.lang.Daemons$Daemon.run+20)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #24 pc 0000000000260bd4 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.4179671085+488)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #25 pc 00000000002666c8 /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #26 pc 0000000000286eb4 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #27 pc 00000000005489b4 /system/lib64/libart.so (MterpInvokeInterface+944)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #28 pc 0000000000572e94 /system/lib64/libart.so (ExecuteMterpImpl+14740)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #29 pc 00000000000cd1ce /system/framework/boot.vdex (java.lang.Thread.run+12)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #30 pc 0000000000260bd4 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.4179671085+488)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #31 pc 0000000000533b90 /system/lib64/libart.so (artQuickToInterpreterBridge+1020)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #32 pc 00000000005896fc /system/lib64/libart.so (art_quick_to_interpreter_bridge+92)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #33 pc 0000000000580588 /system/lib64/libart.so (art_quick_invoke_stub+584)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #34 pc 00000000000d8608 /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #35 pc 000000000047b3e8 /system/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #36 pc 000000000047c4a4 /system/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue*)+424)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #37 pc 00000000004a8238 /system/lib64/libart.so (art::Thread::CreateCallback(void*)+1120)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #38 pc 0000000000083a6c /system/lib64/libc.so (__pthread_start(void*)+36)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #39 pc 00000000000246e4 /system/lib64/libc.so (__start_thread+68)
I am currently trying to make an application with libgdx on android.
The application is working fine on emulator of android studio but there is a crash with my real phone when I do a world.destroy(body) with the library box2d.
More precisely, during the execution of the game, the application destroys 2 bodys after a collision like it is suppose to do but after 1 sec the app crash.
Here is the code of my listener of collision.
#Override
public void beginContact(Contact contact) {
Body a = contact.getFixtureA().getBody();
Body b = contact.getFixtureB().getBody();
if ((BodyUtils.bodyIsWater(b) && BodyUtils.bodyIsEnemy(a))|| (BodyUtils.bodyIsEnemy(b) && BodyUtils.bodyIsWater(a))){
if (!remove.contains(a)) {
remove.add(a);
}
if (!remove.contains(b)) {
remove.add(b);
}
iswater = false;
}
else if(BodyUtils.bodyIsGround(b) && BodyUtils.bodyIsWater(a)){
if(!remove.contains(a)) {
remove.add(a);
}
iswater=false;
}
else if(BodyUtils.bodyIsGround(a) && BodyUtils.bodyIsWater(b)){
if(!remove.contains(b)) {
remove.add(b);
}
iswater=false;
}
a=null;
b=null;
}
Comment about the code: Water is the bullet which shoot the ennemy. Remove is the arraylist.
Here is the code of my act method which destroy the body that are inside my arraylist of body to destroy ( the collision method but body to destroy into the arraylist ). The destroy call is into the for loop.
#Override
public void act(float delta) {
super.act(delta);
// Fixed timestep
accumulator += delta;
while (accumulator >= delta) {
world.step(TIME_STEP, 10, 10);
accumulator -= TIME_STEP;
}
for (int i = 0; i < remove.size(); i++) {
world.destroyBody(remove.get(i));
remove.remove(i);
/*for (int n = 0; i < y.getJointList().size; n++){
world.destroyJoint(y.getJointList().get(n).joint);
}*/
}
if(add%100==0 && !iswater) {
Array<Body> bodies = new Array<Body>(world.getBodyCount());
world.getBodies(bodies);
for (Body body : bodies) {
update(body);
}
}
if(add%80==0){
createEnemy();
}
add++;
}
Here is the content of the update methode :
private void update(Body body) {
if (BodyUtils.bodyIsEnemy(body) && !iswater) {
EnemyUserData z = (EnemyUserData) body.getUserData();
Vector2 m=body.getPosition();
if(m.x<23f){
createWater(z,m);
iswater=true;
}
}
}
First, I tried to figure out where to problem was from and I found that the app was not crashing if a wasn't destroying bodies. So know I know that the destroy function makes the app crash.
Here is the Sigsegv log:
04-03 19:01:50.068 25361-25404/com.mygdx.game A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7a99fd63c0 in tid 25404 (GLThread 3290)
[ 04-03 19:01:50.076 402: 402 W/ ]
debuggerd: handling request: pid=25361 uid=10171 gid=10171 tid=25404
04-03 19:01:50.174 25501-25501/? A/DEBUG: *** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** ***
04-03 19:01:50.174 25501-25501/? A/DEBUG: Build fingerprint: 'HUAWEI/PRA-LX1/HWPRA-H:7.0/HUAWEIPRA-LX1/C432B196:user/release-keys'
04-03 19:01:50.174 25501-25501/? A/DEBUG: Revision: '0'
04-03 19:01:50.174 25501-25501/? A/DEBUG: ABI: 'arm64'
04-03 19:01:50.174 25501-25501/? A/DEBUG: pid: 25361, tid: 25404, name: GLThread 3290 >>> com.mygdx.game <<<
04-03 19:01:50.174 25501-25501/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7a99fd63c0
04-03 19:01:50.174 25501-25501/? A/DEBUG: x0 0000007a99fd63c0 x1 00000000000000b8 x2 0000007899f841c0 x3 0000000000000002
04-03 19:01:50.174 25501-25501/? A/DEBUG: x4 0000000000000001 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
04-03 19:01:50.174 25501-25501/? A/DEBUG: x8 000000789a2e8098 x9 0000000000000000 x10 0000000000000001 x11 0000000000000001
04-03 19:01:50.174 25501-25501/? A/DEBUG: x12 000000789a91d718 x13 000000789a91d7b4 x14 00000078b7ab1150 x15 0000000000000060
04-03 19:01:50.174 25501-25501/? A/DEBUG: x16 000000789a2e7a18 x17 000000789a2b99d8 x18 0000000000000001 x19 0000007899f841c0
04-03 19:01:50.175 25501-25501/? A/DEBUG: x20 00000078b6888760 x21 0000007899f84200 x22 0000000000000006 x23 00000078b0a86fa0
04-03 19:01:50.175 25501-25501/? A/DEBUG: x24 0000000000000048 x25 604eae760b11fb4a x26 00000078b80d5698 x27 00000078b80d5600
04-03 19:01:50.175 25501-25501/? A/DEBUG: x28 000000789a91d7b0 x29 000000789a91d6d0 x30 000000789a2bd004
04-03 19:01:50.175 25501-25501/? A/DEBUG: sp 000000789a91d6a0 pc 000000789a2b9a34 pstate 0000000080000000
04-03 19:01:50.180 25501-25501/? A/DEBUG: backtrace:
04-03 19:01:50.180 1295-1316/? I/Bluetooth_framework: BluetoothManagerService:Message: 401
04-03 19:01:50.181 25501-25501/? A/DEBUG: #00 pc 000000000001ba34 /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (_ZN16b2BlockAllocator8AllocateEi+92)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #01 pc 000000000001f000 /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (_ZN7b2World10CreateBodyEPK9b2BodyDef+48)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #02 pc 000000000002f6d0 /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (Java_com_badlogic_gdx_physics_box2d_World_jniCreateBody+160)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #03 pc 00000000000db790 /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #04 pc 00000000000d21b4 /system/lib64/libart.so (art_quick_invoke_stub+580)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #05 pc 00000000000dee80 /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+204)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #06 pc 000000000028cbf0 /system/lib64/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+312)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #07 pc 0000000000286cac /system/lib64/libart.so (_ZN3art11interpreter6DoCallILb1ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+444)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #08 pc 00000000005556e4 /system/lib64/libart.so (MterpInvokeDirectRange+384)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #09 pc 00000000000c4f94 /system/lib64/libart.so (ExecuteMterpImpl+15252)
[ 04-03 19:01:50.536 402: 402 W/ ]
debuggerd: resuming target 25361
I've also tested an emulator which have the same android version of my phone and it worked. ( it is version 7 api 24 ). So it isn't the problem.
ps: I don't destroy twice a body (I've put some condition to avoid it).
I am a noob of libgdx please help <3 (and sorry for my bad english!)
EDIT : To answers a question in the comment of "Subrata M" here is the logcat if i put the destroy method after the update and the createEnemy().
04-03 20:26:59.973 29708-29747/com.mygdx.game A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7a9a07b400 in tid 29747 (GLThread 3385)
04-03 20:26:59.974 2497-2497/? I/WearableService: Wearable Services stopping
[ 04-03 20:26:59.976 402: 402 W/ ]
debuggerd: handling request: pid=29708 uid=10171 gid=10171 tid=29747
04-03 20:27:00.017 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.025 1600-1600/? I/EventCenter: EventCenter Get :android.intent.action.TIME_TICK
04-03 20:27:00.032 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.039 1600-1600/? E/DateLunarView: mDateString is: mar 3 avr
04-03 20:27:00.042 1600-1600/? E/DateLunarView: mDateString is: mar 3 avr
04-03 20:27:00.054 2572-2572/? I/HwLauncher: Model onReceive intent=Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }
04-03 20:27:00.054 2572-2572/? I/HwLauncher: Model onReceive user=UserHandle{0}
04-03 20:27:00.079 29868-29868/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-03 20:27:00.079 29868-29868/? A/DEBUG: Build fingerprint: 'HUAWEI/PRA-LX1/HWPRA-H:7.0/HUAWEIPRA-LX1/C432B196:user/release-keys'
04-03 20:27:00.079 29868-29868/? A/DEBUG: Revision: '0'
04-03 20:27:00.079 29868-29868/? A/DEBUG: ABI: 'arm64'
04-03 20:27:00.079 29868-29868/? A/DEBUG: pid: 29708, tid: 29747, name: GLThread 3385 >>> com.mygdx.game <<<
04-03 20:27:00.079 29868-29868/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7a9a07b400
04-03 20:27:00.079 29868-29868/? A/DEBUG: x0 0000007a9a07b400 x1 00000000000000b8 x2 0000007899b36980 x3 0000000000000002
04-03 20:27:00.079 29868-29868/? A/DEBUG: x4 0000000000000001 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
04-03 20:27:00.079 29868-29868/? A/DEBUG: x8 000000789775e098 x9 0000000000000000 x10 0000000000000001 x11 0000000000000001
04-03 20:27:00.079 29868-29868/? A/DEBUG: x12 000000789aa1a7e8 x13 000000789aa1a884 x14 00000078b7ab1150 x15 0000000000000060
04-03 20:27:00.079 29868-29868/? A/DEBUG: x16 000000789775da18 x17 000000789772f9d8 x18 0000000000000001 x19 0000007899b36980
04-03 20:27:00.079 29868-29868/? A/DEBUG: x20 00000078b687a270 x21 0000007899b369c0 x22 0000000000000006 x23 00000078b6a13fa0
04-03 20:27:00.079 29868-29868/? A/DEBUG: x24 0000000000000048 x25 604eae760b11fb4a x26 00000078a908ca98 x27 00000078a908ca00
04-03 20:27:00.079 29868-29868/? A/DEBUG: x28 000000789aa1a880 x29 000000789aa1a7a0 x30 0000007897733004
04-03 20:27:00.079 29868-29868/? A/DEBUG: sp 000000789aa1a770 pc 000000789772fa34 pstate 0000000080000000
04-03 20:27:00.087 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.089 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.092 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.094 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.097 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.098 29868-29868/? A/DEBUG: backtrace:
04-03 20:27:00.098 29868-29868/? A/DEBUG: #00 pc 000000000001ba34 /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (_ZN16b2BlockAllocator8AllocateEi+92)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #01 pc 000000000001f000 /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (_ZN7b2World10CreateBodyEPK9b2BodyDef+48)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #02 pc 000000000002f6d0 /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (Java_com_badlogic_gdx_physics_box2d_World_jniCreateBody+160)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #03 pc 00000000000db790 /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #04 pc 00000000000d21b4 /system/lib64/libart.so (art_quick_invoke_stub+580)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #05 pc 00000000000dee80 /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+204)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #06 pc 000000000028cbf0 /system/lib64/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+312)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #07 pc 0000000000286cac /system/lib64/libart.so (_ZN3art11interpreter6DoCallILb1ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+444)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #08 pc 00000000005556e4 /system/lib64/libart.so (MterpInvokeDirectRange+384)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #09 pc 00000000000c4f94 /system/lib64/libart.so (ExecuteMterpImpl+15252)
04-03 20:27:00.123 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
04-03 20:27:00.131 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
04-03 20:27:00.136 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
[ 04-03 20:27:00.390 402: 402 W/ ]
debuggerd: resuming target 29708
EDIT2 : I asked two friends to test the app. the first has got a oneplus 3t and it doesn't crash. The other has got a Huawei Mate 9 and it crash.
This is most certainly a box2d allocation issue and not a phone/make specific issue. What you can do is to set the body object to null when you destroy it and you will see what is happening.
Try this:
for (int i = 0; i < remove.size(); i++) {
world.destroyBody(remove.get(i));
remove.get(i) = null;
/*for (int n = 0; i < y.getJointList().size; n++){
world.destroyJoint(y.getJointList().get(n).joint);
}*/
}
remove.clear();
I am currently developing an application where after the camera detected a body, an image (shirt) will be overlaid. However, after detecting the body, the camera crashes and my logcat says Fatal signal 6 (SIGABRT), code -6 in tid 23908 (Thread-39833).
Below are the codes I've made so far.
nerds_thesis_clartips_OpencvClass.h //header file
#include <jni.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
#ifndef _Included_nerds_thesis_clartips_OpencvClass
#define _Included_nerds_thesis_clartips_OpencvClass
#ifdef __cplusplus
extern "C" {
#endif
void detectHuman(Mat& frame);
Mat putShirt(Mat frame, Point center, Size humanSize);
JNIEXPORT void JNICALL Java_nerds_thesis_clartips_OpencvClass_humanDetection
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif
nerds_thesis_clartips_OpencvClass.cpp //C++ file
#include "nerds_thesis_clartips_OpencvClass.h"
JNIEXPORT void JNICALL Java_nerds_thesis_clartips_OpencvClass_humanDetection
(JNIEnv *, jclass, jlong addrRgba){
Mat& frame = *(Mat*)addrRgba;
detectHuman(frame);
}
void detectHuman(Mat& frame){
// assign xml file to a variable
String human_cascade_name = "/storage/emulated/0/data/haarcascade_upperbody.xml";
CascadeClassifier human_cascade;
// load xml file
if(!human_cascade.load( human_cascade_name ) ) { printf("--(!)Error loading\n"); return; };
std::vector<Rect> humans;
Mat frame_gray;
//convert input to grayscale
cvtColor( frame, frame_gray, CV_BGR2GRAY );
//increase image contrast
equalizeHist( frame_gray, frame_gray);
//Detect Human
human_cascade.detectMultiScale( frame_gray, humans, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(100, 100) );
// Draw the mask over all rectangles
for (size_t i = 0; i < humans.size(); i++){
Rect r = humans[i];
Mat humanROI = frame_gray( humans[i] ); //image of the upper body
int h_temp = humans[i].height; // storing original height
int x = humans[i].x;
int y = humans[i].y - h_temp*(-0.6); // y is increased by 0.6*h
int w = humans[i].width;
int h = h_temp; // height detected
rectangle(frame, Point(x,y), Point(x + w,y +h),Scalar(255,0,255));
Point center( humans[i].x + humans[i].width*0.5, humans[i].y + humans[i].height*0.5 );
frame = putShirt(frame,center,Size( humans[i].width, humans[i].height));
}
}
Mat putShirt(Mat frame, Point center, Size humanSize){
Mat mask = imread("C:/Users/Requinala/AndroidStudioProjects/CLARTIPS/app/src/main/res/drawable/bluevelvet.png");
Mat mask1,src1;
resize(mask,mask1,humanSize);
// ROI selection
Rect roi(center.x - humanSize.width/2, center.y - humanSize.width/2, humanSize.width, humanSize.width);
frame(roi).copyTo(src1);
// to make the white region transparent
Mat mask2,m,m1;
cvtColor(mask1,mask2,CV_BGR2GRAY);
threshold(mask2,mask2,230,255,CV_THRESH_BINARY_INV);
vector<Mat> maskChannels(3),result_mask(3);
split(mask1, maskChannels);
bitwise_and(maskChannels[0],mask2,result_mask[0]);
bitwise_and(maskChannels[1],mask2,result_mask[1]);
bitwise_and(maskChannels[2],mask2,result_mask[2]);
merge(result_mask,m ); // imshow("m",m);
mask2 = 255 - mask2;
vector<Mat> srcChannels(3);
split(src1, srcChannels);
bitwise_and(srcChannels[0],mask2,result_mask[0]);
bitwise_and(srcChannels[1],mask2,result_mask[1]);
bitwise_and(srcChannels[2],mask2,result_mask[2]);
merge(result_mask,m1 ); // imshow("m1",m1);
addWeighted(m,1,m1,1,0,m1); // imshow("m2",m1);
m1.copyTo(frame(roi));
return frame;
}
OpencvCamera.java //Java class for camera
public class OpencvCamera extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2{
Mat mRgba;
#Override
public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
}
#Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
OpencvClass.humanDetection(mRgba.getNativeObjAddr());
return mRgba;
}
}
OpencvClass.java //java class for the jni
public class OpencvClass {
public native static void humanDetection(long addrRgba);
}
logcats
02-24 16:45:36.269 13615-23908/? A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 23908 (Thread-39833)
02-24 16:45:36.372 280-280/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-24 16:45:36.372 280-280/? I/DEBUG: Build fingerprint: 'CMCC/M631Y/M631Y:5.1.1/LMY47V/M631Y_02.24.00RPD_HK.00:user/release-keys'
02-24 16:45:36.372 280-280/? I/DEBUG: Revision: '0'
02-24 16:45:36.372 280-280/? I/DEBUG: ABI: 'arm'
02-24 16:45:36.373 280-280/? I/DEBUG: pid: 13615, tid: 23908, name: Thread-39833 >>> nerds.thesis.clartips <<<
02-24 16:45:36.373 280-280/? I/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
02-24 16:45:36.396 280-280/? I/DEBUG: r0 00000000 r1 00005d64 r2 00000006 r3 00000000
02-24 16:45:36.396 280-280/? I/DEBUG: r4 a4674dd8 r5 00000006 r6 00000000 r7 0000010c
02-24 16:45:36.396 280-280/? I/DEBUG: r8 00000047 r9 00000001 sl a4674400 fp 0000203e
02-24 16:45:36.397 280-280/? I/DEBUG: ip 00005d64 sp a46732a0 lr b6dbfc2d pc b6de5f3c cpsr 600f0010
02-24 16:45:36.397 280-280/? I/DEBUG: backtrace:
02-24 16:45:36.397 280-280/? I/DEBUG: #00 pc 00039f3c /system/lib/libc.so (tgkill+12)
02-24 16:45:36.397 280-280/? I/DEBUG: #01 pc 00013c29 /system/lib/libc.so (pthread_kill+52)
02-24 16:45:36.397 280-280/? I/DEBUG: #02 pc 00014847 /system/lib/libc.so (raise+10)
02-24 16:45:36.397 280-280/? I/DEBUG: #03 pc 00010fd5 /system/lib/libc.so (__libc_android_abort+36)
02-24 16:45:36.397 280-280/? I/DEBUG: #04 pc 0000f534 /system/lib/libc.so (abort+4)
02-24 16:45:36.397 280-280/? I/DEBUG: #05 pc 008a2e50 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN9__gnu_cxx27__verbose_terminate_handlerEv+344)
02-24 16:45:36.398 280-280/? I/DEBUG: #06 pc 0087914c /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN10__cxxabiv111__terminateEPFvvE+4)
02-24 16:45:36.398 280-280/? I/DEBUG: #07 pc 0087918c /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZSt9terminatev+16)
02-24 16:45:36.398 280-280/? I/DEBUG: #08 pc 00878b68 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (__cxa_throw+168)
02-24 16:45:36.398 280-280/? I/DEBUG: #09 pc 001c8305 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN2cv5errorERKNS_9ExceptionE+244)
02-24 16:45:36.398 280-280/? I/DEBUG: #10 pc 001c8445 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN2cv5errorEiRKNS_6StringEPKcS4_i+96)
02-24 16:45:36.398 280-280/? I/DEBUG: #11 pc 0037660f /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi+406)
02-24 16:45:36.399 280-280/? I/DEBUG: #12 pc 0000fbf5 /data/app/nerds.thesis.clartips-2/lib/arm/libMyLibs.so (putShirt+172)
02-24 16:45:36.399 280-280/? I/DEBUG: #13 pc 0000f7ab /data/app/nerds.thesis.clartips-2/lib/arm/libMyLibs.so (detectHuman+842)
02-24 16:45:36.399 280-280/? I/DEBUG: #14 pc 0015fc6d /data/dalvik-cache/arm/data#app#nerds.thesis.clartips-2#base.apk#classes.dex
I'm a beginner and I've searched about SIGABRT and it says it has something to do about memory issues. I can't find where I've gone wrong in my codes.
This is very crucial. All helps/ideas will be appreciated because this will serve as my final output in college.
imread("C:/Users/Requinala/AndroidStudioProjects/CLARTIPS/app/src/main/res/drawable/bluevelvet.png")
tires to read the png from your PC disk. No wonder that it fails. You should
always check that result of file read, etc. is OK
read the image from your phone storage, or from assets of your app
You can use Java to extract images from the resources (or assets) to local storage, or you can use the Android assets native API to read such images directly from the APK.
Assets seem to suit your cause better, because the drawable resources are meant to be adapted to the screen resolution.
Using native assets API with imread() is possible, but tricky.
An error occurs at times (more often than not, actually).
A/libc: Fatal signal 11 (SIGSEGV) at 0x830ab2cc (code=1), thread 24294 (Thread-1174)
The code is as follows:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.displaygraph);
Intent intent = getIntent();
GraphView graph = (GraphView) findViewById(R.id.graph);
series = new LineGraphSeries<DataPoint>();
graph.addSeries(series);
Viewport viewport = graph.getViewport();
viewport.setYAxisBoundsManual(true);
viewport.setXAxisBoundsManual(true);
viewport.setMinY(0);
double max=data[0];
for (int i = 0; i < data.length; i++) {
if (data[i] > max) {
max = data[i];
Log.w(TAG,"max"+max);
}
}
viewport.setMaxY(max);
viewport.setMinX(0);
viewport.setMaxX(450);
graph.getViewport().setScalable(true);
graph.getViewport().setScalableY(true);
seriesecg = new LineGraphSeries<DataPoint>();
GraphView graphecg = (GraphView) findViewById(R.id.graphecg);
graphecg.addSeries(seriesecg);
Viewport viewportecg = graphecg.getViewport();
viewportecg.setYAxisBoundsManual(true);
viewportecg.setXAxisBoundsManual(true);
viewportecg.setMinY(0);
viewportecg.setMaxY(3000);
viewportecg.setMinX(0);
viewportecg.setMaxX(450);
graphecg.getViewport().setScalable(true);
graphecg.getViewport().setScalableY(true);
}
#Override
protected void onResume() {
super.onResume();
new Thread(new Runnable() {
#Override
public void run() {
// we add 450 new entries
for (int i = 0; i <= 449; i++) {
final int finalI = i;
final int finalII = i;
Log.w(TAG, "finalI"+finalI);
runOnUiThread(new Runnable() {
#Override
public void run() {
addEntry(finalI,ppg);
}
});
// sleep to slow down the add of entries
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// manage error ...
}
}
}
}).start();
}
// add random data to graph
private void addEntry(int i,double[] data) {
if(i<=449) {
Log.w(TAG, "ppg" + data[i]+"/"+i);
series.appendData(new DataPoint(i, data[i]), false, 450);
}
}
The logcat is as follows:
01-22 19:27:01.650 1041-1370/? I/KeyguardUpdateMonitor: visibility is same
01-22 19:27:01.650 818-818/? D/CrashAnrDetector: Build: samsung/lt03ltezs/lt03lte:4.4.2/KOT49H/P605ZSUCOD1:user/release-keys
Hardware: MSM8974
Revision: 11
Bootloader: P605ZSUCOD1
Radio: unknown
Kernel: Linux version 3.4.0-4665213 (dpi#SWDD5621) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Mon Apr 13 11:19:19 KST 2015
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/lt03ltezs/lt03lte:4.4.2/KOT49H/P605ZSUCOD1:user/release-keys'
Revision: '11'
pid: 12476, tid: 12476, name: elerometergraph >>> com.android.accelerometergraph <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 82f5583c
r0 402aaedb r1 82f55838 r2 402aaed8 r3 42caa968
r4 bedfd1b8 r5 42277008 r6 bedfd20c r7 402aaaa8
r8 00000000 r9 42caad98 sl 416b049c fp 80000000
ip 00000003 sp bedfd010 lr 4172ff51 pc 4172ff3e cpsr 900f0030
d0 0080000000001000 d1 0200000000004000
d2 0000000000000008 d3 0000888800000000
d4 0000004080000000 d5 0000200000000000
d6 1000000000200000 d7 0000800000000010
d8 44618b1844624bf2 d9 3e99999a4040da00
d10 43380000c3892666 d11 c389266644618b18
d12 4252ccd044624bf2 d13 c07124cccccccccd
d14 4034000000000000 d15 43a38000c3892666
d16 0100000000000000 d17 0004400000020000
d18 0004400000000000 d19 2000010000440000
d20 000a402000088100 d21 0000000000044000
d22 0022000000008800 d23 1100000000000000
d24 3fd1b10853a79915 d25 3fd554fa9ca0567a
d26 3fdb6db71408e660 d27 3fe33333332d4313
d28 3ff0000000000000 d29 0000000000000001
d30 4059000000000000 d31 4024000000000000
scr 20000013
backtrace:
#00 pc 00075f3e /system/lib/libdvm.so (mspace_bulk_free+89)
#01 pc 00076e63 /system/lib/libdvm.so (dvmHeapSourceFreeList(unsigned int, void**)+70)
#02 pc 0003a7b4 /system/lib/libdvm.so
#03 pc 0002c4ec /system/lib/libdvm.so (dvmHeapBitmapSweepWalk(HeapBitmap const*, HeapBitmap const*, unsigned int, unsigned int, void (*)(unsigned int, void**, void*), void*)+176)
#04 pc 0003b53c /system/lib/libdvm.so (dvmHeapSweepUnmarkedObjects(bool, bool, unsigned int*, unsigned int*)+284)
#05 pc 0002c94c /system/lib/libdvm.so (dvmCollectGarbageInternal(GcSpec const*)+452)
#06 pc 0002d45c /system/lib/libdvm.so (dvmMalloc(unsigned int, int)+356)
#07 pc 0006cb03 /system/lib/libdvm.so
#08 pc 0002c36f /dev/ashmem/dalvik-jit-code-cache (deleted)
stack:
bedfcfd0 bedfd1ec [stack]
bedfcfd4 40129d5d /system/lib/libc.so (realloc+12)
bedfcfd8 00000008
bedfcfdc bedfd2a8 [stack]
bedfcfe0 78e476f8
bedfcfe4 00000000
bedfcfe8 00000003
bedfcfec bedfd100 [stack]
bedfcff0 42ca9b88 /dev/ashmem/dalvik-heap (deleted)
bedfcff4 bedfd174 [stack]
bedfcff8 42277008 /dev/ashmem/dalvik-heap (deleted)
bedfcffc bedfd20c [stack]
bedfd000 42caa968 /dev/ashmem/dalvik-heap (deleted)
bedfd004 00000000
bedfd008 42caa950 /dev/ashmem/dalvik-heap (deleted)
bedfd00c 4172ff51 /system/lib/libdvm.so (mspace_bulk_free+108)
#00 bedfd010 00029864
bedfd014 416b0438
bedfd018 00000065
bedfd01c 00000065
bedfd020 bedfd078 [stack]
bedfd024 416b0438
bedfd028 42277008 /dev/ashmem/dalvik-heap (deleted)
bedfd02c 41730e67 /system/lib/libdvm.so (dvmHeapSourceFreeList(unsigned int, void**)+74)
#01 bedfd030 00000065
bedfd034 402abf98 /system/lib/libandroidfw.so
bedfd038 bedfd2cc [stack]
bedfd03c bedfd2cc [stack]
bedfd040 00000065
bedfd044 61fff040 /dev/ashmem/dalvik-bitmap-2 (deleted)
bedfd048 617ff040 /dev/ashmem/dalvik-bitmap-1 (deleted)
bedfd04c 0001acbf
bedfd050 bedfd078 [stack]
bedfd054 416f47b8 /system/lib/libdvm.so
#02 bedfd058 00000000
bedfd05c 00000000
bedfd060 00000030
bedfd064 00015010
bedfd068 01501
01-22 19:27:01.650 818-818/? D/CrashAnrDetector: processName:com.android.accelerometergraph
01-22 19:27:01.650 818-818/? D/CrashAnrDetector: broadcastEvent : com.android.accelerometergraph SYSTEM_TOMBSTONE
01-22 19:27:01.660 1041-1055/? D/KeyguardUpdateMonitor: sendKeyguardVisibilityChanged(true)
01-22 19:27:01.660 1041-1055/? I/KeyguardUpdateMonitor: visibility is same
Sometimes the code works but sometimes it doesn't... but when it occurs, it does so before the value of i reaches 449. I thought it had something to do with my jni code. but after commenting and deleting everything that would call a c code, the error still occurred.
Thank you for your help...
I have an Android App, in which I have below class containing fields of both native (C++) objects wrapped with JNI, and other java objects:
class MyClass
{
Node nativeNode; // containing Native objects wrapped using NDK and JNI
long otherVars; // some java instances
public void dispose()
{
freeNativeNode();
}
}
In my app, I continuously create instances of MyClass:
for(int i=0;i<1000;i++)
{
MyClass obj = new MyClass();
...
obj.freeNativeNode(); // Here, free native resources (A)
//System.gc(); // Here explicitly collect memory (B)
}
The app crashes when i is bigger than some number, e.g. when i>400 or i>450.
Since I have freed the native memory explicitly as in line (A) above, so I think there should be no memory leak, and java shall use garbage collection to revoke the memory. But the app crashes, and I suspect it might be a memory leak problem.
As I know, it is possible to free the managed memory in Java by calling:
System.GC();
I tried to call this in (B) above, however, the app crashes more often, and say when i > 60, it already crashes.
My questions are:
[1] Should I call System.GC() explicitly? As many have different opinions on calling this ourselves, and some say this is not a good practice.
[2] How do I elegantly free the memory in the loop to avoid crash?
Edit: I understand it is less appropriate to print full log here, but it might be useful to get the whole picture for troubleshooting the problem.
From the log, it seems to be not a memory leak problem, but one of my colleague believes so, and I have no strong evidence showing this is NOT, :)
The tombstone log: debuggerd: 2014-05-01 23:56:47
Build fingerprint: 'htc_asia_hk/endeavoru/endeavoru:4.1.1/JRO03C/128187.28:user/release-keys'
pid: 31725, tid: 31725, name: com.cityu.scm >>> com.cityu.scm <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000003
r0 000ff7ff r1 ffffffff r2 00000000 r3 ffffffff
r4 00000110 r5 553b36f8 r6 00000008 r7 00000000
r8 00000000 r9 48ce1c44 sl 40c5b020 fp bec7761c
ip 00000110 sp bec76db0 lr 400491b7 pc 400497b6 cpsr a0000030
d0 0000000000000008 d1 3ddb7cdfd9d7bdbb
d2 3fece61cf8e1788d d3 4435800000000000
d4 000002d0000002d6 d5 0000000042000000
d6 44340000435f0000 d7 0000000040000000
d8 00000000440a8000 d9 0000000000000000
d10 0000000000000000 d11 0000000000000000
d12 0000000000000000 d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 0000000000000000 d17 0000000000000001
d18 0000000000000000 d19 3ff0000000000000
d20 0000000000000000 d21 0000000000000000
d22 0000000000000000 d23 0000000000000000
d24 3ff0000000000000 d25 3ff0000000000000
d26 0000000000000000 d27 c053000000000000
d28 0000000000000006 d29 3ff0000000000000
d30 3ff0000000000000 d31 3ff0000000000000
scr 20000011
backtrace:
#00 pc 000147b6 /system/lib/libc.so (dlmalloc+1589)
#01 pc 00017123 /system/lib/libc.so (malloc+10)
#02 pc 003774fc /data/data/com.cityu.scm/lib/libjniosg.so (operator new(unsigned int)+24)
stack:
bec76d70 5516df70
bec76d74 bec77608 [stack]
bec76d78 48ce1c44
bec76d7c 40c5b020
bec76d80 c0000000
bec76d84 0000001b
bec76d88 0000000e
bec76d8c 003ef75c
bec76d90 0000000e
bec76d94 bec77310 [stack]
bec76d98 c0000000
bec76d9c 00000108
bec76da0 00000000
bec76da4 003ef75c
bec76da8 df0027ad
bec76dac 00000000
#00 bec76db0 524af370
bec76db4 53dc0677 /data/data/com.cityu.scm/lib/libjniosg.so
bec76db8 00000000
bec76dbc 53dc0b15 /data/data/com.cityu.scm/lib/libjniosg.so
(std::_Rb_tree >, std::_Select1st > >, std::less, std::allocator > > >::find(std::string const&)+58)
bec76dc0 00000000
bec76dc4 00000108
bec76dc8 524af160
bec76dcc 003ef75c
bec76dd0 00000164
bec76dd4 bec77608 [stack]
bec76dd8 48ce1c44
bec76ddc 40c5b020
bec76de0 bec7761c [stack]
bec76de4 4004c125 /system/lib/libc.so (malloc+12)
#01 bec76de8 53cbd8ad /data/data/com.cityu.scm/lib/libjniosg.so
bec76dec 53c09500 /data/data/com.cityu.scm/lib/libjniosg.so (operator new(unsigned int)+28)
#02 bec76df0 00000000
bec76df4 524af160
bec76df8 bec7724c [stack]
bec76dfc 53cbd8b7 /data/data/com.cityu.scm/lib/libjniosg.so
bec76e00 00000000
bec76e04 53dc5af9 /data/data/com.cityu.scm/lib/libjniosg.so
(osgDB::InputStream::readObjectFields(std::string const&, unsigned int, osg::Object*)+80)
bec76e08 bec76e34 [stack]
bec76e0c 00000009
bec76e10 bec7724c [stack]
bec76e14 53c1a70b /data/data/com.cityu.scm/lib/libjniosg.so
(BinaryInputIterator::readUInt(unsigned int&)+14)
bec76e18 bec7724c [stack]
bec76e1c bec77288 [stack]
bec76e20 bec7724c [stack]
bec76e24 bec7724c [stack]
bec76e28 00000000
bec76e2c 53dc5c53 /data/data/com.cityu.scm/lib/libjniosg.so
(osgDB::InputStream::readObject(osg::Object*)+114)
memory near r0:
000ff7dc ffffffff ffffffff ffffffff ffffffff ................
000ff7ec ffffffff ffffffff ffffffff ffffffff ................
000ff7fc ffffffff ffffffff ffffffff ffffffff ................
000ff80c ffffffff ffffffff ffffffff ffffffff ................
000ff81c ffffffff ffffffff ffffffff ffffffff ................
memory near r5:
553b36d8 00000000 00000000 53ffa940 553b3701 ........#..S.7;U
553b36e8 00000000 00000000 00000000 00000000 ................
553b36f8 00000000 00000111 553b15f0 553b0b68 ..........;Uh.;U
553b3708 ffffffff 00000000 524133b8 00000000 .........3AR....
553b3718 00000020 000000f1 552da1d0 552fd620 .........-U ./U
memory near r9:
48ce1c24 4cdbee30 4bc88be8 00000006 48ce1c5c 0..L...K....\..H
48ce1c34 5270279c 4bff8370 00000006 00000000 .'pRp..K........
48ce1c44 4390001d 48ce1c84 526f0310 4bff83a8 ...C...H..oR...K
48ce1c54 5270279c 00000000 48ce1c84 526f0308 .'pR.......H..oR
48ce1c64 4bc81c28 00000006 410ace98 48ce1cbc (..K.......A...H
memory near sl:
40c5b000 00000000 00000000 00000000 00000453 ............S...
40c5b010 4cd06328 48ce1c44 4bff83a8 52486000 (c.LD..H...K.`HR
40c5b020 8b300dd1 00001d30 bec77730 00000000 ..0.0...0w......
40c5b030 bec77764 00000001 00000000 40791380 dw............y#
40c5b040 00000000 00000000 402e0570 48cdc300 ........p..#...H
memory near fp:
bec775fc 54f4c024 4bff8370 407911f4 48ce1c44 $..Tp..K..y#D..H
bec7760c 00000001 4119d1f8 52722f8f 0000003b .......A./rR;...
bec7761c 407c3c87 48ce1c44 52722f8d 53bc6a01 .<|#D..H./rR.j.S
bec7762c 40c5b020 a3a00019 00000000 4082c238 ..#........8..#
bec7763c 40085a98 00000022 40103033 40cdbb10 .Z.#"...30.#...#
memory near sp:
bec76d90 0000000e bec77310 c0000000 00000108 .....s..........
bec76da0 00000000 003ef75c df0027ad 00000000 ....\.>..'......
bec76db0 524af370 53dc0677 00000000 53dc0b15 p.JRw..S.......S
bec76dc0 00000000 00000108 524af160 003ef75c ........`.JR\.>.
bec76dd0 00000164 bec77608 48ce1c44 40c5b020 d....v..D..H ..#
code around pc:
40049794 0240f3c0 66a8f8df f102fa30 0c02eb03 ..#....f0.......
400497a4 0501eb0c eb06447e 25000085 312cf8d0 ....~D.....%..,1
400497b4 685ae00d f0226919 ebc40c03 4542020c ..Zh.i".......BE
400497c4 4642bf2c b901461d 460b6959 2b004690 ,.BF.F..Yi.F.F.+
400497d4 2d00d1ef 818ff000 2668f8df 6890447a ...-......h&zD.h
code around lr:
40049194 b930fd11 2becf8df f8d2447a 078b11b4 ..0....+zD......
400491a4 f8dfd50a 447d5be4 70dcf505 f7fe2500 .....[}D...p.%..
400491b4 2800e886 8249f041 f2002cf4 2c0a823f ...(A.I..,..?..,
400491c4 340bd903 0407f024 2410e000 7bbcf8df ...4$......$...{
400491d4 447f08e2 fa36683e 079df302 f003d042 ...D>h6.....B...
pid: 31725, tid: 31727, name: GC
r0 fffffffc r1 00000080 r2 fffffffc r3 4fe62e30
r4 40cdbbb0 r5 40cdbbac r6 fffffffc r7 000000f0
r8 00001388 r9 00000000 sl 4082df98 fp 00000001
ip 00000000 sp 4fe62e10 lr 40047f80 pc 40042ca4 cpsr 60000010
d0 42c80000428cea01 d1 3ff00000003db190
d2 0000000100000001 d3 b684088000080000
d4 0000000040dc8000 d5 000000000006e400
d6 00578fe000000963 d7 000000464dc0cae2
d8 0000000000000000 d9 0000000000000000
d10 0000000000000000 d11 0000000000000000
d12 0000000000000000 d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 4139200000000000 d17 4132d9f000000000
d18 0033003200310030 d19 0000000000000000
d20 4008000000000000 d21 3fbc71c71c71c71c
d22 3fcc7288e957b53b d23 3fd24998d6307188
d24 3fd99a27ad32ddf5 d25 3fe555b0aaeac752
d26 0000000000000000 d27 0000000000000000
d28 0000000000000005 d29 0000000000000000
d30 0000000000000000 d31 0000000000000000
scr 80000010
backtrace:
#00 pc 0000dca4 /system/lib/libc.so (__futex_syscall3+12)
#01 pc 00012f7c /system/lib/libc.so (__pthread_cond_timedwait_relative+48)
#02 pc 00012fd8 /system/lib/libc.so (__pthread_cond_timedwait+60)
#03 pc 00057029 /system/lib/libdvm.so (dvmRelativeCondWait(pthread_cond_t*, pthread_mutex_t*, long long, int)+112)
#04 pc 00078655 /system/lib/libdvm.so
#05 pc 000591e7 /system/lib/libdvm.so
#06 pc 00012e48 /system/lib/libc.so (__thread_entry+72)
#07 pc 0001257c /system/lib/libc.so (pthread_create+208)
stack:
4fe62dd0 01e9b4a6
4fe62dd4 7fffffff
4fe62dd8 01e9b50c
4fe62ddc 0004e200
4fe62de0 0000fa00
4fe62de4 40046314 /system/lib/libc.so (__divdi3+244)
4fe62de8 01e9b517
4fe62dec 4082c238 /system/lib/libdvm.so
4fe62df0 40cdbab0 [heap]
4fe62df4 00000000
4fe62df8 4fe62e00
4fe62dfc 000003e8
4fe62e00 00000000
4fe62e04 00001388
4fe62e08 00000000
4fe62e0c 00001388
#00 4fe62e10 40cdbbb0 [heap]
4fe62e14 4fe62e30
#01 4fe62e18 00000001
4fe62e1c 40cdbbac [heap]
4fe62e20 40cdbbb0 [heap]
4fe62e24 40cdbbb0 [heap]
4fe62e28 40cdbbac [heap]
4fe62e2c 40047fdc /system/lib/libc.so (__pthread_cond_timedwait+64)
#02 4fe62e30 00000004
4fe62e34 3b9ac618
4fe62e38 4fe62e40
4fe62e3c 1c09ac61
4fe62e40 00007d62
4fe62e44 407ca02d /system/lib/libdvm.so (dvmRelativeCondWait(pthread_cond_t*, pthread_mutex_t*, long long, int)+116)
#03 4fe62e48 00007d62
4fe62e4c 1c09ac61
4fe62e50 00001388
4fe62e54 407eb765 /system/lib/libdvm.so
4fe62e58 4082df98
4fe62e5c 00000000
4fe62e60 00000001
4fe62e64 407cc19d /system/lib/libdvm.so
4fe62e68 00100000
4fe62e6c 407eb659 /system/lib/libdvm.so
#04 4fe62e70 00000000
4fe62e74 00000001
4fe62e78 00000001
4fe62e7c 00000000
4fe62e80 00000008
4fe62e84 40c725e0
4fe62e88 4082c238 /system/lib/libdvm.so
4fe62e8c bec77768 [stack]
4fe62e90 00000078
4fe62e94 407cc19d /system/lib/libdvm.so
4fe62e98 00100000
4fe62e9c 40c725e0
4fe62ea0 00000001
4fe62ea4 407cc1e9 /system/lib/libdvm.so
#05 4fe62ea8 40c725e0
4fe62eac 00010002
4fe62eb0 40ccbc80
4fe62eb4 40cea080 /dev/ashmem/dalvik-heap (deleted)
4fe62eb8 4fe62f00
4fe62ebc 40c725e0
4fe62ec0 407cc190 /system/lib/libdvm.so (dvmDetachCurrentThread()+763)
4fe62ec4 40047e4c /system/lib/libc.so (__thread_entry+76)
#06 4fe62ec8 00000000
4fe62ecc 00000000
4fe62ed0 00000000
4fe62ed4 00000000
4fe62ed8 00000000
4fe62edc 4fe62f00
4fe62ee0 40cce0a0
4fe62ee4 bec77770 [stack]
4fe62ee8 00000078
4fe62eec 407cc19d /system/lib/libdvm.so
4fe62ef0 00100000
4fe62ef4 40c725e0
4fe62ef8 00000001
4fe62efc 40047580 /system/lib/libc.so (pthread_create+212)
#07 4fe62f00 4fe62f00
4fe62f04 40cce0a0
4fe62f08 00000000
4fe62f0c 00000000
4fe62f10 00000000
4fe62f14 00000000
4fe62f18 4e68a460
4fe62f1c 00000000
4fe62f20 00000000
4fe62f24 00000000
4fe62f28 00000000
4fe62f2c 00000000
4fe62f30 00000000
4fe62f34 00000000
4fe62f38 00000000
4fe62f3c 00000000
pid: 31725, tid: 31729, name: Signal Catcher
r0 fffffffc r1 00000000 r2 00000000 r3 00000008
r4 4ff62e58 r5 40828261 r6 bec77778 r7 000000b1
r8 407cc19d r9 52415800 sl 5010be38 fp 00042e74
ip 40827e6c sp 4ff62e18 lr 4004f453 pc 40042554 cpsr 20000010
d0 42c800004266db5b d1 3ff00000002aff38
d2 0000000100000001 d3 b684088000080000
d4 0000000040dc8000 d5 000000000006e400
d6 004a7ff000000963 d7 000000394d865d8f
d8 0000000000000000 d9 0000000000000000
d10 0000000000000000 d11 0000000000000000
d12 0000000000000000 d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 40d3000000000000 d17 40c3cc0000000000
d18 0033003200310030 d19 0000000000000000
d20 4008000000000000 d21 3fbc71c71c71c71c
d22 3fcc7288e957b53b d23 3fd24998d6307188
d24 3fd99a27ad32ddf5 d25 3fe555b0aaeac752
d26 0000000000000000 d27 0000000000000000
d28 0000000000000005 d29 0000000000000000
d30 0000000000000000 d31 0000000000000000
scr 80000010
backtrace:
#00 pc 0000d554 /system/lib/libc.so (__rt_sigtimedwait+12)
#01 pc 0001a44f /system/lib/libc.so (sigwait+20)
#02 pc 00055fcf /system/lib/libdvm.so
#03 pc 000591e7 /system/lib/libdvm.so
#04 pc 00012e48 /system/lib/libc.so (__thread_entry+72)
#05 pc 0001257c /system/lib/libc.so (pthread_create+208)
stack:
4ff62dd8 00000000
4ff62ddc 00000000
4ff62de0 00000000
4ff62de4 00000000
4ff62de8 00000000
4ff62dec 00000000
4ff62df0 40827c88 /system/lib/libdvm.so
4ff62df4 52415800
4ff62df8 4bc64570 /dev/ashmem/dalvik-LinearAlloc (deleted)
4ff62dfc 4ff62e78
4ff62e00 4ff62e78
4ff62e04 40cbffc4
4ff62e08 4ce76760 /system/framework/core.odex
4ff62e0c 4ff62e78
4ff62e10 00000000
4ff62e14 407d9c21 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+276)
#00 4ff62e18 4ff62e58
4ff62e1c 40811cfc /system/lib/libdvm.so
#01 4ff62e20 00000204
4ff62e24 00000000
4ff62e28 5010be38
4ff62e2c 407c8fd3 /system/lib/libdvm.so
#02 4ff62e30 00000001
4ff62e34 40cea080 /dev/ashmem/dalvik-heap (deleted)
4ff62e38 4bc64570 /dev/ashmem/dalvik-LinearAlloc (deleted)
4ff62e3c 40003310
4ff62e40 52415b6c
4ff62e44 407c88ef /system/lib/libdvm.so (dvmRemoveFromReferenceTable(ReferenceTable*, Object**, Object*)+30)
4ff62e48 52415800
4ff62e4c 00042e8a
4ff62e50 410a0ec8 /dev/ashmem/dalvik-heap (deleted)
4ff62e54 00000204
4ff62e58 ffffffe0
4ff62e5c 52415800
4ff62e60 410a0ec8 /dev/ashmem/dalvik-heap (deleted)
4ff62e64 407cb485 /system/lib/libdvm.so (dvmAttachCurrentThread(JavaVMAttachArgs const*, bool)+452)
4ff62e68 40cea080 /dev/ashmem/dalvik-heap (deleted)
4ff62e6c 410a0ec8 /dev/ashmem/dalvik-heap (deleted)
........ ........
#03 4ff62ea8 5010be38
4ff62eac 00010002
4ff62eb0 40c6d380
4ff62eb4 40cea080 /dev/ashmem/dalvik-heap (deleted)
4ff62eb8 4ff62f00
4ff62ebc 5010be38
4ff62ec0 407cc190 /system/lib/libdvm.so (dvmDetachCurrentThread()+763)
4ff62ec4 40047e4c /system/lib/libc.so (__thread_entry+76)
#04 4ff62ec8 00000000
4ff62ecc 00000000
4ff62ed0 00000000
4ff62ed4 00000000
4ff62ed8 00000000
4ff62edc 4ff62f00
4ff62ee0 40cce8f8
4ff62ee4 bec77780 [stack]
4ff62ee8 00000078
4ff62eec 407cc19d /system/lib/libdvm.so
4ff62ef0 00100000
4ff62ef4 5010be38
4ff62ef8 00000001
4ff62efc 40047580 /system/lib/libc.so (pthread_create+212)
#05 4ff62f00 4ff62f00
4ff62f04 40cce8f8
4ff62f08 00000000
4ff62f0c 00000000
4ff62f10 00000000
4ff62f14 00000000
4ff62f18 52415800
4ff62f1c 00000000
4ff62f20 00000000
4ff62f24 00000000
4ff62f28 00000000
4ff62f2c 00000000
4ff62f30 00000000
4ff62f34 00000000
4ff62f38 00000000
4ff62f3c 00000000
pid: 31725, tid: 31730, name: JDWP
r0 00000031 r1 50062de0 r2 00000000 r3 00000000
r4 00000000 r5 00000000 r6 00000000 r7 0000008e
r8 501011b0 r9 00000030 sl 0003b777 fp 00000001
ip 50062dc0 sp 50062db0 lr 407dad43 pc 40041cb4 cpsr 40000010
d0 42c800004266db5b d1 3ff00000002aff38
d2 0000000100000001 d3 b684088000080000
d4 0000000040dc8000 d5 000000000006e400
d6 004a7ff000000963 d7 000000394d865d8f
d8 0000000000000000 d9 0000000000000000
d10 0000000000000000 d11 0000000000000000
d12 0000000000000000 d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 40d3000000000000 d17 40c3cc0000000000
d18 0033003200310030 d19 0000000000000000
d20 4008000000000000 d21 3fbc71c71c71c71c
d22 3fcc7288e957b53b d23 3fd24998d6307188
d24 3fd99a27ad32ddf5 d25 3fe555b0aaeac752
d26 0000000000000000 d27 0000000000000000
d28 0000000000000005 d29 0000000000000000
d30 0000000000000000 d31 0000000000000000
scr 80000010
backtrace:
#00 pc 0000ccb4 /system/lib/libc.so (select+16)
#01 pc 00067d3f /system/lib/libdvm.so
#02 pc 0006acd1 /system/lib/libdvm.so
#03 pc 000591e7 /system/lib/libdvm.so
#04 pc 00012e48 /system/lib/libc.so (__thread_entry+72)
#05 pc 0001257c /system/lib/libc.so (pthread_create+208)
[1] Should I call System.GC() explicitly? As many have different
opinions on calling this ourselves, and some say this is not a good
practice.
Probably not. As previously mentioned by user3580294, System.GC() is really only a suggestion to the VM and what it does when you call that method directly is totally up to the implementation. I would never use this function to prevent a program from crashing.
[2] How do I elegantly free the memory in the loop to avoid crash?
What exactly is using up all the memory? Clearly when MyClass is
constructed some native resouces are being created... Are these JNI
objects? Are they C alloced memory?
I am going to go out on a limb here based on the backtrace and say that the objects eating up all your memory are JNI objects that were created in C/C++ (probably on a separate thread) and passed back to the JVM. Try calling DeleteLocalRef() on the JNI object(s) that are passed back to the VM.
Again, my above suggestion is based on a lot of assumption. You really need to attach a memory profiler like jvisualvm to the JVM to see exactly what is using up all the memory and then determine why the GC didn't catch it. (Hint: there is probably still a reference to it)