Using "terminate" declare prevents app profiling completion

As many of us have learned, 64bit Mac OS apps will crash on close if we have any code in CancelClose. To solve this, a call to a Cocoa function “terminate” is used:

[code] #If targetMacOS Then
Declare Function NSClassFromString Lib “Cocoa” ( aClassName As CFStringRef ) As Integer
Declare Function sharedApplication Lib “Cocoa” selector “sharedApplication” ( classRef As Integer ) As Integer
Declare Sub terminate Lib “Cocoa” selector “terminate:” ( appRef As Integer, sender As Integer )

Dim appInstance As Integer = sharedApplication( NSClassFromString( "NSApplication" ) )
terminate( appInstance, appInstance )

#EndIf[/code]
There is a bad side effect from this if you are trying to profile you code - the profile summary is discarded since the profiler stub thinks that the app exit improperly.

So, we either get a profiler result with a probable app crash on quit, or we don’t get the profiler report.

Questions - for @Joe Ranieri :
Is the crash on quit being resolved

for others:
Do you use Profiling in your built apps for BETA and, if so, have you run into and worked around this?

as far as I know app must quit properly to transfer measurements back to IDE, so you can’t use terminate.

I’m not running in the IDE - I need results from actual use cases at the customer location. In the IDE, I can simply add an “If Not DebugBuild Then” block around the terminate declares code and ignore the crash.

Which begs the next question - why doesn’t the profile result get returned even IF the app “crashes” before quit?

The application shut down mechanism handles the writing of the profile data from memory. If the app crashes this can’t happen.

The IDE has code in its application instance cancel close event handler and doesn’t crash on quit so this must depend on what code is in there.

a) Write your own profiling
b) use XCode instead (mostly kidding)

I’m interested in this, too, because I have the opposite problem. My app doesn’t quit at all in 64bit. <https://xojo.com/issue/48395> . The chances of getting this fixed are pretty low.

Is it still the case? I tried your test app with 2018r1.1 and it quits on macOS 64 Bit.

  1. Yes; am still using macOS 10.11 for development; where this API is not required to exit correctly.
  2. However I do use this API when not profiling so that I can get the “Resume” functionality.
  3. I’ve started to use my own profiler; the main reason being is that it writes the results as it goes along. This allows me to get a lossy overview of what the changes do in real time. It still has many many kinks and doesn’t work correctly, so I suspect it needs a rebuild.