iPhone -Uiimage Leak, Objectalloc Building
-
07-07-2019 - |
문제
좋아, 나는이 메모리 누출을 추적하는 데 어려움을 겪고있다. 이 스크립트를 실행할 때 메모리가 새는 것을 보지 못하지만 내 대상이 등반됩니다. 악기는 cgbitmapcontextcreateimage> create_bitmap_data_provider> malloc을 가리 킵니다. 이것은 내 대상의 60%를 차지합니다.
이 코드는 NSTIMER로 여러 번 호출됩니다.
반환 후 reuiimage를 어떻게 지우나요?
... 또는 uiimage image withcgimage가 내 대상을 구축하지 않도록 어떻게 만들 수 있습니까?
//I shorten the code because no one responded to another post
//Think my ObjectAlloc is building up on that retUIImage that I am returning
//**How do I clear that reUIImage after the return?**
-(UIImage) functionname {
//blah blah blah code
//blah blah more code
UIImage *retUIImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return retUIImage;
}
해결책
이 방법을 사용하면 uiimage를 인스턴스화하고 자동 제출로 설정합니다. 이것들을 정리하려면 정기적으로 수영장을 비워야합니다.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
..
..
..
[pool release];
이것들은 중첩 될 수 있습니다.
NSAutoreleasePool *pool1 = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
..
..
..
[pool2 release];
[pool1 release];
일반적인 관행은 루프 및 많은 자동 퇴행 객체를 만드는 다른 방법에 대해 주위에 배치하는 것입니다.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (Thing *t in things) {
[thing doAMethodThatAutoreleasesABunchOfStuff];
}
[pool release]
제휴하지 않습니다 StackOverflow