Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppDelegate deconstructor is not called on Android #14110

Closed
rynkowsg opened this issue Oct 11, 2015 · 5 comments
Closed

AppDelegate deconstructor is not called on Android #14110

rynkowsg opened this issue Oct 11, 2015 · 5 comments

Comments

@rynkowsg
Copy link
Contributor

I used at AppDelegate's deconstructor a log, and it was not printed.
I was looking and I found that AppDelegate object is created on the heap and probably it is not released.
Please look on the Android's main.cpp:

void cocos_android_app_init (JNIEnv* env) {
    LOGD("cocos_android_app_init");
    AppDelegate *pAppDelegate = new AppDelegate();
}

Does it should be like this?

@FrankStain
Copy link

@rynkowsg , all it's totally true.
It's an cocos2d-x design issue, and it's very hard to fix it. Jni and Java design must be changed to fix this issue.
Currently there is no place in java code, where Application could be safely finalized.

@rynkowsg
Copy link
Contributor Author

@FrankStain
Thanks for the clarification.

rynkowsg pushed a commit to hopstertv/cocos2d-x that referenced this issue Aug 6, 2016
AppDelegate object and all its members are never released.
As a solution I propose to use static unique_ptr that could destroy it
at the end of the application.

Issue:
cocos2d#14110
rynkowsg pushed a commit to hopstertv/plugin-x that referenced this issue Aug 6, 2016
AppDelegate object and all its members are never released.
As a solution I propose to use static unique_ptr that could destroy it
at the end of the application.

Issue:
cocos2d/cocos2d-x#14110
@rynkowsg rynkowsg reopened this Aug 6, 2016
@rynkowsg
Copy link
Contributor Author

rynkowsg commented Aug 6, 2016

@FrankStain,
I reopened the issue because I prepared a solution for it:
#16333
cocos2d-x/plugin-x#174

In my organisation I applied this fix couple months ago and it works perfectly.

@FrankStain
Copy link

@rynkowsg ,
Wow, nice solution!

Frankly, i had never thought in such direction. Also JNI_OnUnload may be used for such purposes.
And, yep, i can confirm, this solution is safe. AppDelegate will be created only one time per library load and removed just before unloading of library (and after invocation of JNI_OnUnload).

minggo pushed a commit that referenced this issue Aug 8, 2016
* Remove AppDelegate memory leak from Android projects

AppDelegate object and all its members are never released.
As a solution I propose to use static unique_ptr that could destroy it
at the end of the application.

Issue:
#14110

* Correct code style in Android main.cpp files

- removed redundant headers (reduced dependencies)
- removed redundant code
- corrected code style
@rynkowsg
Copy link
Contributor Author

rynkowsg commented Aug 8, 2016

My changes have been merged. I'm going to close the issue.

@rynkowsg rynkowsg closed this as completed Aug 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants