Cocos2d-x android 小白 问题

今天看 Hellocpp ,了解android上启动流程,发现下面这个问题,百思不得其解…

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv*  env, jobject thiz, jint w, jint h)
{
    if (!CCDirector::sharedDirector()->getOpenGLView())
    {
        CCEGLView *view = CCEGLView::sharedOpenGLView();
        view->setFrameSize(w, h);


        AppDelegate *pAppDelegate = new AppDelegate();//这个对象在哪里释放的?
        CCApplication::sharedApplication()->run();
    }
    else
    {
        ccGLInvalidateStateCache();
        CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
        ccDrawInit();
        CCTextureCache::reloadAllTextures();
        CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_COME_TO_FOREGROUND, NULL);
        CCDirector::sharedDirector()->setGLDefaultValues(); 
    }
}
```
int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);


    // create the application instance
    AppDelegate app;
    CCEGLView* eglView = CCEGLView::sharedOpenGLView();
    eglView->setViewName("HelloCpp");
    eglView->setFrameSize(2048, 1536);
    // The resolution of ipad3 is very large. In general, PC's resolution is smaller than it.
    // So we need to invoke 'setFrameZoomFactor'(only valid on desktop(win32, mac, linux)) to make the window smaller.
    eglView->setFrameZoomFactor(0.4f);
    return CCApplication::sharedApplication()->run();
}


```


win32上 AppDelegate 在main函数中创建在栈上,而android确实new出来的,开始我猜测AppDelegate 是push进了autorelease pool,但是查找代码,怎么也没发现push的地方。

有知道这个问题的朋友吗,不胜感激!!!!

android不用自己释放, 垃圾自动回收啊

AppDelegate不是java对象,java通过 JNI 调用C++代码在本地堆中创建的对象。

垃圾回收只能回收JAVA对象,AppDelegate是个C++写的类,这种对象,gc管不了。

这…只能帮顶了:12:

不用管这个,写代码就好了,那是引擎的事。