2012-03-24 7 views
2

Ich erhalte Bild von URL durch Threading. aber Speicherverlust in NSData. Warum? Wie repariere ich es? In Iphone devie undicht im Simulator. Hilf mir!!Speicherverlust Verwendung von NSData von URL

// Viewcontroller

-(void)viewDidLoad 
{ 

[self performSelectorInBackground:@selector(loadImageScreenshot:) withObject:args]; 

} 

// Loding Bild

-(void) loadImageScreenshot:(NSDictionary *) args 
{ 
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
UIImage * screenshotImage=[UIImage imageWithStringURL:url]; 
NSDictionary *args2=[NSDictionary dictionaryWithObjectsAndKeys: 
        [NSNumber numberWithInt:num], @"screenNum", 
        screenshotImage,@"image", 
        nil];                

[self performSelectorOnMainThread:@selector(assignImageToScreenshotImageView:) withObject:args2 waitUntilDone:YES]; 

[pool release]; 

} 

// Bild hinzufügen

- (void) assignImageToScreenshotImageView:(NSDictionary *)arg 

{ 

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
UIImage * image= [arg objectForKey:@"image"]; 
UIImageView *imageview=[UIImageView alloc]init]; 
       . 
       . 
imageview.image=image; 
[self.mScreenshotSpace addSubview:imageview]; 
[imageview release]; 
[pool release]; 
} 

// Bild von url

+(UIImage *)imageWithStringURL:(NSString *)strURL 
{ 
NSURL *url =[NSURL URLWithString:strURL]; 
NSData * data=[[NSData alloc]initWithContentsOfURL:url options:NSDataReadingUncached error:&error]; 

UIImage * image=[UIImage imageWithData:data ]; 
[data release]; 
return image; 
} 

Antwort

1

Woher weißt du, dass es undicht ist? Sie erstellen einen Autorelease-Pool in - (void) assignImageToScreenshotImageView:(NSDictionary *)arg, der nie leer ist, dh ein Leck. Sonst scheint der Code in Ordnung.

+0

In Verwendung des Geräts undichtem Speicher. - (void) assignImageToScreenshotImageView: (NSDictionary *) Arg ist ein Problem? Wie repariere ich es? – SeoTaiJi

+1

Sie haben jetzt die '[pool release]' Zeile hinzugefügt, sieht gut aus für mich. – Tark

Verwandte Themen