Memory Management with Static Fields

Discussion in 'iOS Programming' started by Lakario, Oct 31, 2008.

  1. macrumors member

    Oct 29, 2008
    In one of my application classes (subclass of TableCell) I create some static fields that are initialized for the whole class.

    static UIImage *checkedImage = nil;
    @implementation ItemCell
    +(void)initialize {
    	checkedImage = [[UIImage imageNamed:@"checkbox_checked.png"] retain];
    As far as memory management is concerned, where should these items be released? Is there a static dealloc?
  2. macrumors regular

    Mar 24, 2008
    I don't think you really need to release those. When the app quits, any memory allocated to is immediately reclaimed. So for objects that need to exist for the entire life of your running application, I wouldn't worry about it.

    Although, I would happy to know of a cleaner way from someone smarter than I.
  3. thread starter macrumors member

    Oct 29, 2008
    This thread seems to essentially reiterate what you said. Thanks for the input. :)
  4. macrumors 68030


    Sep 2, 2008
    In general you don't release these kinds of objects.

    However, you could treat it as a singleton. In that case it would be loaded lazily, not inside +initialize. And you could release it and nil the variable if you got a memory warning. It would be reloaded if it was needed after that.

Share This Page