On Apr 19, 2025, at 04:53, Gabriel Zachmann via Cocoa-dev <cocoa-dev@lists.apple.com> wrote: > > > Is there an easy way to check, if other instances are still running?
I log stuff to see what's going on. Either using standard logging (OSLog, etc) or write to your own file if trying to filter in Console is too horrible (which it is). Here's how I keep track of instances created (for each run and for each screen). My LOG is a #define that can do different types of logging or none for release builds. The class variable will only be created once when the screensaver is loaded, but each screen's instance will increment it when initted, and decrement when stopped. static NSUInteger sNumViewsMade; @interface BlahScreenSaverView @property (class) NSUInteger numViewsMade; @end @implementation BlahScreenSaverView +(NSUInteger) numViewsMade { return sNumViewsMade; } +(void) setNumViewsMade:(NSUInteger)nvm { sNumViewsMade = nvm; } -(instancetype) initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview { BlahScreenSaverView.numViewsMade++; LOG(@"BlahScreenSaverView: initWithFrame, isPreview = %d, frame = %@, numViewsMade = %lu", isPreview, NSStringFromRect(frame), BlahScreenSaverView.numViewsMade); Normal init stuff here… } -(void) stopAnimation { [super stopAnimation]; BlahScreenSaverView.numViewsMade—; LOG(@"BlahScreenSaverView: Stopping animation for screen %@, numViewsMade = %lu", self.isPreview ? @"Prefs" : @(screenIndex).stringValue, BlahScreenSaverView.numViewsMade); if(BlahScreenSaverView.numViewsMade == 0) { // No more instances should be running: if(!self.isPreview && !self.runningFromSSTest) [NSException raise:@"BlahScreenSaverView" format:@"Kill legacyScreenSaver because it sucks and will keep running and won't remove our views."]; } } @end -- Steve Mills Drummer, Mac geek _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com