background image for UIButton

Discussion in 'iPhone/iPad Programming' started by jagatnibas, Nov 15, 2009.

  1. macrumors regular

    i am doing something like below

    UIImage *img = [UIImage imageNamed:@"a.png"];
    UIButton *btn =[[valid instance from nib file]]
    [btn setbackgroundImage:img forState:UIControlStateNormal];
    [img release];
    shouldnot i be able to release img ?
    because i dont need the image anymore i ca release img, isn;t it ?

    in UIImageView we are able to do that, in button why not ?

    like in

    UIImageView = alloc
    add subview: imgview
    [img release];
    [imgview release];
    it just works fine !

  2. Moderator


    Staff Member

    Go and read the memory management guide: you should not release img as you do not create it with an alloc/init or copy constructor so it is autoreleased.
  3. macrumors newbie

    Normally it releases the image object.:rolleyes:
  4. Moderator


    Staff Member

    Normally what releases the object? That makes no sense.
  5. macrumors newbie

    If we do

    UIImage *img = [UIImage imageNamed:@"1.png"];
    [img release];
    Because after assigning it you dont need the object of UIImage.

    If you are more interested in memory management (UIImage) please go through this link i hope it helps because it helped me a lot. :)


Share This Page