我該如何解決這個內存泄漏問題?我有一個NSBezierPath的集合嗎?我該如何解決這個內存泄漏問題?有什麼建議?我正在使用ARC。Objective-C NSImage,內存泄漏(任何建議)我正在使用ARC
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
for(int j=0;j<5000;j++){
NSLog(@"Hello, World!");
NSSize imageSize = NSMakeSize(512, 512);
NSImage *image = [[NSImage alloc] initWithSize:imageSize];
//draw a line:
for(int i=0;i<1000;i++){
[image lockFocus];
float r1 = (float)(arc4random() % 500);
float r2 = (float)(arc4random() % 500);
float r3 = (float)(arc4random() % 500);
float r4 = (float)(arc4random() % 500);
[NSBezierPath strokeLineFromPoint:NSMakePoint(r1, r2) toPoint:NSMakePoint(r3, r4)];
}
//...
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, imageSize.width, imageSize.height)];
NSData *pngData = [imageRep representationUsingType:NSPNGFileType properties:nil];
[image unlockFocus];
NSString *jstring = [NSString stringWithFormat:@"%d", j];
jstring = [jstring stringByAppendingString:@".png"];
[pngData writeToFile:jstring atomically:YES];
}
}
return 0;
}
你說得對,我很新。我喜歡製作5000張帶有隨機線條的照片。 – user1735714