Eric Roller's Development Blog

Use of dealloc

- Posted in macOS by

After spending a few days trying to figure out why my log file was not truncated correctly, I re-discovered a feature of the Objective-C runtime: The dealloc method is never called - at least not to my knowledge.

Therefore, do not add mission-critical code in the dealloc method of a class; use a dedicated custom method instead, for instance:

- (void) close
    [theLog truncateFileAtOffset:[theLog offsetInFile]];
    [theLog closeFile];