所以我用Core Data
來存儲幾張圖像。 (另外,子類與最新mogenerator
生成)核心數據永不釋放從外部存儲加載的NSData
(也是我使用ARC)
是的,我知道我可以只保留引用並將其存儲在磁盤上,但我認爲:
「嘿,他們提出了一個選擇,所以我可以做到這一點,而無需自己管理它!」
所以我試了一下,它的工作原理除了所有加載數據的方式都是從未發佈。
在ViewController中誰的要負責顯示圖像的初始化我給它平時主要NSManagedObjectContext
。
而在一個名爲方法viewDidAppear
我成立了UIScrollView
與圖像:
編輯: 所以它不是一個真正的讀取請求我有一個Entity1
其中有一個一對多的圖片和我用它來獲取圖像 我從同一個上下文中獲得這個entity1。我只是想簡化以更好地解釋。
- (void)setupScrollViewWithEntity1:(Entity1 *)entity1 {
DDLogVerbose(@"-- %@ : SETUP SCROLL VIEW --", self);
// I remove any previous subviews
[self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
self.scrollView.contentSize = self.scrollView.frame.size;
/* Here I get the imagesArray with a NSFetchRequest */
//So it's not really a fetch request I have an `Entity1` which have one-to-many with images and I use it to get the images
NSSet *imagesSet = entity1.images;
// So I have an NSArray holding all the Image object
for (Image *image in imagesSet) {
CGRect frame = self.scrollView.frame;
frame.origin.x = image.numberValue*frame.size.width;
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:frame];
scrollView.contentSize = self.scrollView.frame.size;
UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.scrollView.frame];
imageView.image = [UIImage imageWithData:image.image];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.userInteractionEnabled = YES;
[scrollView addSubview:imageView];
scrollView.delegate = self;
scrollView.minimumZoomScale = 1.0;
scrollView.maximumZoomScale = 3.0;
[self.scrollView addSubview:scrollView];
}
}
}
在viewWillDisappear
我保存NSManagedObjectContext
和我希望當控制器被dealloc'ed,所有的數據將過,但它停留在記憶永存。
此行不知何故保留它不知道爲什麼:imageView.image = [UIImage imageWithData:image.image];
我上了3天試圖用一切,Instruments
,複查,如果我沒有保持很強的參考地方。
的東西是UIViewController
得到dealloc
「版,我敢肯定,我看到它在Instruments
與Allocation
工具,但由於某種原因在內存中的數據保持永遠,直到應用崩潰。
這裏的名單〜20幅圖像在內存沒有得到dealloc'ed:
而這裏的第一個對象的細節:
謝謝你閱讀,直到這裏,我是真的絕望:(
你使用的是弧形嗎? – J2theC 2013-03-01 21:26:30
是的,我忘了提及它,但我標記它讓我編輯 – ItsASecret 2013-03-01 21:27:46
受管理的對象上下文是否超越視圖控制器?如果是這樣,你可能只是得到一個帶有循環引用的對象圖,並且你沒有明確地拒絕你的對象。 – Tommy 2013-03-01 21:35:01