No destructor call?

I added some code in the appdelegate destructor, but when i close my app , the destructor is never actually called.

I’m testing on windows phone 8 and cocos2dx 2.2.3.

I know that the engine has its own object releasing method with reference counting, but I would really like to manually release my objects and to know when the app is being closed.

I am not sure about WIndows Phone, but when you “close” the game (by pressing the home button), the game isn’t actually closed. It’s merely sent to background. When you open the app again, it then goes to foreground. This may be the reason why the destructor isn’t called.

Try closing the app forcibly. On Android, it has a Force Close option in the Settings app.

To add to what lance_gray said, why would you want to manually release your objects ? Reference counting is meant to make your life easier so that you don’t have to worry about the exact moment your objects are actually destroyed.

If you need some part of the code to be absolutely executed at a specific time, may be you should use a method akin to Finalize in Java.

I am actually closing the app and not minimizing it. And can you be more specific with the Finalize method?

There surely has to be a way to know when my app is being closed.

In your destructor, you are probably doing 2 things :

  • stopping actions, removing some visuals etc … : you want that to get done at a specific time
  • releasing resources (other objects) : you don’t care when it’s done, as long as it is done

The first should be moved in another method (finalize is what it’s called in Android), and the second should be left in the destructor.

Cocos2d-x AppDelegate have a method called applicationDidEnterBackground, did you try it ? I don’t know the specifics of an app lifecycle on Windows Phone though.

I cannot release the resources when the app is in background, that would mean actually closing it when the user doesn’t want to.

What I’m asking here, is: where do I find a C++ (not java) function that actually gets called when the app is actually closed, and not put into the background?

Just noticed: the application entered foreground and entered background functions are not called on windows phone at all… is there an actual bug that causes this?

I have actually same problem with you…
But wp 8.1 has a kind of solution.
When App is closed, cocos2d::App’s destructor is called.(not AppDelegate)
cocos2d::App is in App.xaml.cpp. What about use this one?