ImageIO initImageJPEG instances get allocated and never released

I am developing an application for the iPhone, and found that the following code causes an increase in memory.

    -(UIImage *)createRecipeCardImage:(Process *)objectTBD atIndex:(int)indx
{

[objectTBD retain];

// bringing the image for the background 
UIImage *rCard = [UIImage imageNamed:@"card_bg.png"];
CGRect frame = CGRectMake(00.0f, 80.0f, 330.0f, 330.0f); 

// creating he UIImage view to contain the recipe data
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = rCard;

[rCard release];
imageView.userInteractionEnabled = YES;


float titleLabelWidth = 150.0;
float leftGutter = 5.0;
float titleYPos = 25.0;
float space = 3.0;
float leftYPos = 0;

// locating Title label
float currentHeight = [self calculateHeightOfTextFromWidth:objectTBD.Title :titleFont :titleLabelWidth :UILineBreakModeWordWrap];
UILabel *cardTitle = [[UILabel alloc]initWithFrame:CGRectMake(leftGutter, titleYPos, titleLabelWidth, currentHeight)];
cardTitle.lineBreakMode = UILineBreakModeWordWrap;
cardTitle.numberOfLines = 0;
cardTitle.font = titleFont;
cardTitle.text = objectTBD.Title;
cardTitle.backgroundColor = [UIColor clearColor];
[imageView addSubview:cardTitle];

[cardTitle release];

leftYPos = titleYPos + currentHeight + space;

// locating brown line
UIView *brownLine = [[UIView alloc] initWithFrame:CGRectMake(5.0, leftYPos, 150.0, 2.0)];
brownLine.backgroundColor = [UIColor colorWithRed:0.647 green:0.341 blue:0.122 alpha:1.0];
[imageView addSubview:brownLine];

[brownLine release]; 

leftYPos = leftYPos + 2 + space + space + space;

// creating the imageView to place the image
UIImageView *processPhoto = [[UIImageView alloc] initWithFrame:CGRectMake(leftGutter, leftYPos, 150, 150)];


if((uniqueIndex == indx) && (uniqueImg.imageData != nil))
{

    if([uniqueImg.rcpIden isEqualToString:objectTBD.iden])
    {
        objectTBD.imageData = [NSString stringWithFormat:@"%@", uniqueImg.imageData];
        [recipesFound replaceObjectAtIndex:indx withObject:objectTBD];


        NSData * imageData = [NSData dataFromBase64String:objectTBD.imageData];
        UIImage *rcpImage = [[UIImage alloc] initWithData:imageData];
        [imageData release];
        processPhoto.image = rcpImage;
        [rcpImage release];

    }


}
else if(objectTBD.imageData != nil)
{

    NSData * imageData = [NSData dataFromBase64String:objectTBD.imageData];
    UIImage *rcpImage = [[UIImage alloc] initWithData:imageData];
    processPhoto.image = rcpImage;
    [rcpImage release];
    [decodedBigImageDataPointers addObject:imageData];

}
else
{
    UIImage * rcpImage =  [UIImage imageNamed:@"default_recipe_img.png"];
    processPhoto.image = rcpImage;
    [rcpImage release];
}

NSlog(@" Process Photo Retain Count %i", [processPhoto retainCount]); // this prints a 1
[imageView addSubview:processPhoto]; 

NSlog(@" Process Photo Retain Count %i", [processPhoto retainCount]); // this prints a 2!!!!
//[processPhoto release];  // this line causes an error :( 



// converting the UIImageView into a UIImage
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[objectTBD release];

for(UIView *eachSubview in imageView.subviews)
{
    [eachSubview removeFromSuperview];
    NSLog(@"each subview retainCount %i  despues", [eachSubview retainCount]);
    // here I find that the processPhoto view has a retain count of 2 (all other views have their retain count in 1)
}

return viewImage;

}

When I checked the selection of tool objects, I found that "GeneralBlock-9216" was growing.

Breaking the line, I found that every time I call this code, one instance:

2 0x5083800 00:18.534 ImageIO initImageJPEG

. When checking the call stack, the following line is highlighted:

UIImage * objImage = [UIImage imageWithData:imageData];

Any help finding a bug?

+5
source share
3 answers

TechZen, imageWithXXX: ( ). initWithXXX: release API imageWithXXX:.

, , , , .

, . , .

+2

- ? , , . .

:

, imageWithContentsOfFile ( initWithContentsOfFile, ). , , , initImageJPEG Malloc 9.00 KB, .

:. , : , dealloc'd, , (/ ) .. . , , . , , , , .

- NSLogs dealloc . , , ​​ , ( , ) . , . , , , , , .

, . , ​​, , . ( "alloc]", , , - if() - .)

, "Build and Analyze" , .

!

+2

, UIImage. , initWithData:cache, . , , .

, . , OpenGl. , , .

+1
source

All Articles