AppDelegate destructor is not called for android

I am using cocos2d-x-2.1.5. The problem is for Android platform.

AppDelegate is created in generated Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit with new operator. But it looks like it is not deleted anywhere.
So, AppDelegate destructor is not called.
I would like to free some singleton classes used in game logic there.

Is it an architectural issue? Can this problem be fixed for Android?

On Windows AppDelegate is created on stack, so it is automatically destroyed after main function is finished.

can anyone answer this question? the CCDirector destructor also is not called

Use the latest version, and if you really think you have a problem you should post how you’re measuring it.

if you are not seeing log output, make sure that your logging output isn’t being stripped or ignored.

Saying “not calling the DTOR” without describing how you’re measuring the DTOR is not going to get us anywhere.

I use a three singletons controlled in AppDelegate and a dozen calls in CCDIrector are obviously working =)

I have switched to cocos2d-x-2.2.1. But I still see the problem for Android platform.

Short description:
I compile the code with define COCOS2D_DEBUG=1.
I can see the log message printed from AppDelegate constructor, but cannot not see the log message added to AppDelegate destructor. Also I do not see any “cocos2d: deallocing CCDirector …” message from CCDirector.
Details:
I\ have\ added\ log\ messages:
CCLOG("AppDelegate: constructor.");
CCLOG("AppDelegate: destructor.");
to\ AppDelegate\ constructor\ and\ destructor\ accordingly.
Also,\ I\ added\ log\ message:
CCLOG("Exit scene.");
before\ the\ call\ of\ CCDirector::sharedDirector()->end();
Android\ Log:
When\ I\ run\ the\ application\ on\ Android,\ in\ the\ eclipse\ output\ marked\ with\ “cocos2d-x\ debug\ info”\ I\ have:
*AppDelegate:\ constructor.

\ cocos2d.x.version:\ 2.2.1
\ cocos2d.x.compiled_with_profiler:\ false
\ cocos2d.x.compiled_with_gl_state_cache:\ true
\ gl.vendor:\ Qualcomm
\ gl.renderer:\ Adreno\ 205
\ gl.version:\ OpenGL\ ES\ 2.0\ 1403843
\ gl.max_texture_size:\ 4096
\ gl.max_texture_units:\ 20
\ gl.supports_PVRTC:\ false
\ gl.supports_NPOT:\ true
\ gl.supports_BGRA8888:\ false
\ gl.supports_discard_framebuffer:\ false
\ gl.supports_vertex_array_object:\ false

Exit\ scene.
*
Windows\ Log:
But\ when\ I\ run\ the\ application\ on\ Windows\ I\ can\ see:
AppDelegate:\ constructor.

\ cocos2d.x.version:\ 2.2.1
\ cocos2d.x.compiled_with_profiler:\ false
\ cocos2d.x.compiled_with_gl_state_cache:\ true
\ gl.vendor:\ NVIDIA\ Corporation
\ gl.renderer:\ GeForce\ 9600\ GT/PCI/SSE2
\ gl.version:\ 3.3.0
\ gl.max_texture_size:\ 8192
\ gl.max_texture_units:\ 96
\ gl.supports_PVRTC:\ false
\ gl.supports_NPOT:\ true
\ gl.supports_BGRA8888:\ false
\ gl.supports_discard_framebuffer:\ false
\ gl.supports_vertex_array_object:\ true

Exit\ scene.
cocos2d:\ deallocing\ CCDirector\ 00CE6420
AppDelegate:\ destructor.

Problem:
So,\ on\ Android\ messages\ about\ deallocing\ CCDirector\ and\ AppDelegate\ destructor\ are\ missed.
“cocos2d:\ deallocing\ CCDirector\ 00CE6420”
“AppDelegate:\ destructor.”

And\ it\ looks\ like
CCDirector and ~AppDelegate are not called.

I do not see in code where the AppDelegate is supposed to be deleted on Android version.

As for CCDirector I added some more log messages in its purgeDirector() method and it is called, but the last log message is printed before the call: m_pobOpenGLView->end();. But log messages are not printed after that.
CCEGLView::end() just call terminateProcessJNI(); that calls Cocos2dxHelper::terminateProcess() that calls android.os.Process.killProcess(android.os.Process.myPid());

Could you please help to fix this problem?

This is probably connected with the: BUG: Direcror->end leads to Android killing process instead of finishing activity
http://www.cocos2d-x.org/forums/6/topics/15645?r=29502

The other question is about the following scenario on Android: the user pressed Home button when our application was running. And after that he ran some other apps and Android system decided to destroy our activity to save space.

Should we purge CCDirector in such case? Otherwise all managed caches and CCDirector are not
freed.

Any success with this? Just met this problem recently. This is a crucial bug - a memory leak. I might be mistaken, but I couldn’t find any place where something like ‘delete AppDelegate::getInstance()’ was called. Under Windows, AppDelegate is created on stack, so it is automatically deleted, but on Android, the situation is different, so who is responsible for the cleanup?