UIImageView setImage Leaks?

We have been looking for a solution to this problem for endless hours. The problem is very simple. I have UIImageViewin nib, I download the image from the Internet and install UIIImageViewwith the image. I am releasing viewController. Dealloc actually receives the call (!) And loads the viewController and image again. This can be done by entering the background mode very simply. Leaks of the device do not report any leaks, but it shows in the distribution that it stores the image in memory and continues to grow.

Basic example:

-(id)init {
    if((self = [super init])) {
        id path = [NSString stringWithFormat:@"http://www.aSite.com/largeImage.jpg"];
        NSData* urlData = [[NSData alloc] initWithContentsOfURL:url];
        UIImage* img = [[UIImage alloc] initWithData:urlData];
        [background setImage:img];
        [urlData release];
        [img release];
    }
    return self;
}

-(void)dealloc {
    [background release];
    [super dealloc];
}

, UIImageView , CGImage. , . 10-15 2,5 . iOS ( 4-5 ). UIImageView , , ?

CGImage: (iphone) UIImageView setImage: ?

EDIT: abit tierd, . . , "" . , .

+3
4

release URL-

[background setImage:[UIImage imageWithData:urlData]];
[urlData release];
[img release];
+2

.

  [urlData release];
  [background setImage:[UIImage imageWithData:urlData]];

if((self = [super init])) {
        id path = [NSString stringWithFormat:@"http://www.aSite.com/largeImage.jpg"];
        NSData* urlData = [[NSData alloc] initWithContentsOfURL:url];
        UIImage* img = [[UIImage alloc] initWithData:urlData];
        [background setImage:img];
        [urlData release];
        [img release];
    }
+1

You cannot replace

[background setImage:[UIImage imageWithData:urlData]];

with

[background setImage:img];

UPDATE

I think this should also help.

if((self = [super init])) {
        id path = [NSString stringWithFormat:@"http://www.aSite.com/largeImage.jpg"];
        NSData* urlData = [[NSData alloc] initWithContentsOfURL:url];
        [background setImage:[UIImage imageWithData:urlData]];
        [urlData release];

    }
0
source

You tried:

-(id)init {
    if((self = [super init])) 
    {

        [background setImage:
             [UIImage imageWithData:
                 [NSData dataWithUrl:
                    [NSUrl urlWithString:
                       @"http://www.aSite.com/largeImage.jpg" ]]]
        ];

    }
    return self;
}

-(void)dealloc {
    [super dealloc];
}

clean and no memory leaks!

0
source

All Articles