Releasing

Discussion in 'iOS Programming' started by estupefactika, Mar 19, 2009.

  1. estupefactika macrumors member

    Joined:
    Feb 16, 2009
    Location:
    Alcobendas (Madrid)
    #1
    Hi, I have a doubt when I release objects, Have I to release NsDictionary, NsMutableDictionary, NsArray, NsMutableArray, NsNumber, etc when I create them with alloc?

    Are there any classes like NSString that its not neccesary? thanks
     
  2. detz macrumors 65816

    Joined:
    Jun 29, 2007
    #2
    Anything you use with alloc needs to be released. The reason your NSString does not have to have it is because you're using a convenience function that returns and autorelease object.
     
  3. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #3
    WHY couldn't they have put garbage collection into the 3.0 SDK, that would be a godsend!
     
  4. estupefactika thread starter macrumors member

    Joined:
    Feb 16, 2009
    Location:
    Alcobendas (Madrid)
    #4
    Is needed to release this?

    UIImage *image =[UIImage imageWithData:imageData];
     
  5. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #5
    No
     
  6. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #6
    Unless you explicitly retain it.
     
  7. caveman_uk Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #7
    Basically if you use alloc, copy or mutableCopy to create the object or explicitly retain the object then it needs releasing. Objects that are otherwise obtained (eg arrayWithObjects: or stringWithFormat:) are autoreleased so do not need to be released (unless YOU retained them).
     

Share This Page