小编use*_*714的帖子

Objective-C NSImage,内存泄漏(任何建议)我正在使用 ARC

我该如何修复这个内存泄漏?我有 NSBezierPath 的集合吗?我该如何修复这个内存泄漏?有什么建议吗?我正在使用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 …
Run Code Online (Sandbox Code Playgroud)

macos memory-leaks objective-c

1
推荐指数
1
解决办法
970
查看次数

标签 统计

macos ×1

memory-leaks ×1

objective-c ×1