Main component destructor function is not called when exiting an app on Android

Dear (pro)Jucers,

Main component destructor function is not called when exiting an app on Android. The same app on Windows works as expected, meaning, main component destructor function is called.

Is this normal? Is there a way to call/execute the main component destructor also on Android?

Thanks!

Does anyone has an idea how to solve/debug this?

I know that it is hard to “believe” that this happens but I have a breakpoint in destructor, I’m also printing something on console and writing something to a file and none of those things happen so the only thing I can assume is that it is not executed.

Same code as a Windows app is working perfectly fine. Is there something special about how Juce app on Android is closed?

Hi there, it’s the same thing on iOS, so one should definitely not count on the destructor being called on mobile devices! I learned this from this very useful post:

1 Like

WOW!! :exploding_head: :woozy_face: :scream:

Good to know that I’m not crazy :sweat_smile: Thanks @aamf !

I made one Android app in Java some time ago and if I remember correctly, destructor was called there normally. So can it be that this is something JUCE specific?

This should definitely be better documented.

I now did some tests on two Android devices (API 26 and 30) and the destructor does get called properly, also on two iOS devices (iOS 15).

What are you testing on?

Still, since under some circumstances the destructor does not get called on mobile devices, people should avoid doing anything important there. No idea if this is a JUCE issue though.

@aamf thanks for being involved!

I’m testing on Android version 13 => API 33; phone Pixel 4a. My destructor is composed of log message and one function for saving app state, in that order. I now tested approx. 10-15 times and only once I’ve seen log message but also then nothing was saved. When in debug mode, breakpoint in destructor never triggered.

This could be something not JUCE specific but Android specific and I agree completely with you, nothing important should be done in destructor because it doesn’t seem to have deterministic behaviour on Android.