0

I create UIViews based on xib files programmaticaly and add them to a scrollView. This works so far. If the amount changes I recreate the grid of UIViews (in my case so called theme thumbs). I remove the old ones before I recreate the new ones. The problem is the memory is never released and for every new creation memory usage piles up. Even if I remove one single thumb the memory isn´t released.

Instruments doesn´t show leaks. Dealloc in my ViewController is never called.

I use ARC and I know that I have to avoid retained references. But clearly I have used them and don´t understand where. It would be great if someone could give me a hint where I did it as I have read a lot of posts here but still don´t understand it. NSZombiesEnabled is off.

My code:

-(void)createGrid
{
    for (UIView *subview in self.scrollView.subviews) {
        if ([subview tag] < 10000 && ![subview isKindOfClass:[UIImageView class]]) {
            [subview removeFromSuperview];
        }
    }
    int col = 0;
    int row = 0;
    [self setupFetchedResultsController];
    for (int i = 0; i<[[self.fetchedResultsController fetchedObjects] count]; i++)
    {
        col = i % THEME_COLUMNS;
        row = i / THEME_COLUMNS;
        ThemeThumbVC *themeThumb = [[ThemeThumbVC alloc] init];
        [self.scrollView addSubview:themeThumb.view];

        // configurate thumb
        themeThumb.managedObjectContext = self.managedObjectContext;
        themeThumb.fetchedResultsController = self.fetchedResultsController;
        themeThumb.theme = [[self.fetchedResultsController fetchedObjects] objectAtIndex:i];
        [themeThumb.themeThumbImage setImage:[UIImage imageWithContentsOfFile:[[[self.fetchedResultsController fetchedObjects] objectAtIndex:i] iconImageURL]]];
        [themeThumb setTag:i];
        [themeThumb.view setTag:i];
        [themeThumb.view setFrame:CGRectMake(col*kThemeGritXOffset+(col*1), row*kThemeGritYOffset, kThemeGritXOffset+1, kThemeGritYOffset)];
        [self addChildViewController:(UIViewController*) themeThumb];
    }
    [self.scrollView setContentSize:CGSizeMake(320, row*kThemeGritYOffset+kThemeGritYOffset)];
}
4

1 回答 1

0

如果拇指视图由子视图控制器封装,那么您是否不需要在某些时候从父视图控制器中删除子视图控制器?

如果子视图控制器没有从父视图控制器中删除,那么我最好的猜测是子视图控制器保留了它的拇指视图。

您是否考虑过使用 UICollectionViewController 来创建拇指视图网格?

于 2013-10-08T19:49:06.900 回答