mindbrix / UIImage-PDF

Simple UIImage PDF renderer category for iOS scalable assets

Home Page:http://blog.mindbrix.co.uk/2012/02/10/ios-scalable-assets/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak

UnsafePointer opened this issue · comments

First, great UIImage extension category, I'm loving it so far. I'm having a hard time trying to clean this huge leak on PDFView drawRect.

I'm using UIImage+PDF to make a gallery thumbnail with the pdf first page with this code:

    UIButton *btnCatalogo;
    UILabel *lblTitulo;
    UILabel *lblUltimaFechaRevision;
    int x = 0;
    int y = 0;
    int index = 0;
    for (Catalogo *catalogo in _catalogosArray) {
        btnCatalogo = [UIButton buttonWithType:UIButtonTypeCustom];
        btnCatalogo.frame = CGRectMake(20 + (315 + 20) * x, 20 + (20 + 315 + 40 + 10) * y, 315, 315);
        btnCatalogo.tag = index;
        [btnCatalogo addTarget:self action:@selector(onClickCatalogoButton:) forControlEvents:UIControlEventTouchUpInside];
        [btnCatalogo setImage:[UIImage imageWithPDFNamed:catalogo.archivo fitSize:CGSizeMake(315, 315)] forState:UIControlStateNormal];
        [_scrollView addSubview:btnCatalogo];
        lblTitulo = [[UILabel alloc] initWithFrame:CGRectMake(20 + (315 + 20) * x, 20 + 315 + 10 + (20 + 315 + 40 + 10) * y, 315, 20)];
        lblTitulo.backgroundColor = [UIColor clearColor];
        lblTitulo.font = [UIFont boldSystemFontOfSize:16.0f];
        lblTitulo.textAlignment = NSTextAlignmentCenter;
        lblTitulo.textColor = [UIColor whiteColor];
        lblTitulo.text = catalogo.titulo;
        [_scrollView addSubview:lblTitulo];
        [lblTitulo release];
        lblUltimaFechaRevision = [[UILabel alloc] initWithFrame:CGRectMake(20 + (315 + 20) * x, 20 + 315 + 10 + 20 + (20 + 315 + 40 + 10) * y, 315, 20)];
        lblUltimaFechaRevision.backgroundColor = [UIColor clearColor];
        lblUltimaFechaRevision.font = [UIFont boldSystemFontOfSize:12.0f];
        lblUltimaFechaRevision.textAlignment = NSTextAlignmentCenter;
        lblUltimaFechaRevision.textColor = [UIColor lightGrayColor];
        if ([catalogo.fechaUltimaRevision isEqualToString:@""]) {
            lblUltimaFechaRevision.text = @"Nunca abierto";
        }
        else {
            lblUltimaFechaRevision.text = catalogo.fechaUltimaRevision;
        }
        [_scrollView addSubview:lblUltimaFechaRevision];
        [lblUltimaFechaRevision release];
        x++;
        if (x == 3) {
            x = 0;
            y++;
        }
        index++;
    }

And I'm getting the leaks on PDFView drawRect, any idea that might be happening?

Thanks in advance,

Renzo Crisóstomo.

Hi Renzo. Can you drill down in Instruments to find out exactly what object is leaking, and the line of code it is happening on?

I notice you have the call to imageWithPDFNamed: inside a loop. In my experience, loops and auto-released objects do not mix well. Have you tried draining the auto release pool? This link could help: http://stackoverflow.com/questions/65427/how-does-the-nsautoreleasepool-autorelease-pool-work

Best,
Nigel.

Hi Renzo. Did you manage to find to the leak?

Best,
Nigel.

Hi Nigel, I try draining the auto release pool manually without success. The leak is still there.

Hi Renzo. Is your project using ARC? UIImage+PDF has not been adapted for ARC yet.

Best,
Nigel.

No, I'm using old school memory management. But I end in the conclusion that UIImage+PDF is no the reason. Inverted Call Tree + Show Obj-C Only on Leaks Instruments show that the leak occurs on [PDFView drawRect:] only when opening full colour pdf files, opening documents or so doesn't leak.

Can you send me a stripped-down project so that I can try to recreate the problem here?

Hi. I've now updated the project to use ARC. I hope this helps with your memory issues.