Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-29-2009, 06:47 PM   #1 (permalink)
ykrsdn
Registered Member
 
Join Date: Jul 2009
Posts: 30
ykrsdn is on a distinguished road
Default problem releasing memory - memoryleaks

So I'm making some filters for my iPhone app and everything goes fine as long as I work with small images, but when I bring in the big life size ones like the one the iPhone camera shoots, I'm experiencing some errors probably caused by memoryleaks or resources not released correctly.

So this is my code for one filter :
PHP Code:
- (IBAction)MonoImage {
    
        
//previoushit checks if a filter was already activated and if it is, it restores it and before applying the new filter, if it isn't it saves the new image to an UIimage called "copyOfimage2".

    
if (previousHit == 1)
    {
        
CGImageRef cgImage = [copyOfImage2 CGImage];
        
image.image = [[UIImage allocinitWithCGImage:cgImage];
        
CGImageRelease(cgImage);
        
    }
    else
    {
        
CGImageRef cgImage = [image.image CGImage];
        
copyOfImage2 = [[UIImage allocinitWithCGImage:cgImage];    
        
CGImageRelease(cgImage);
    }
    
    
previousHit 1;
    
    
CGImageRef inImage image.image.CGImage;         
    
CGContextRef ctx
    
    
    
CFDataRef m_DataRef
    
m_DataRef CGDataProviderCopyData(CGImageGetDataProvider(inImage)); 
    
UInt8 m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef); 
    
Byte tmpByte
    
int length CFDataGetLength(m_DataRef); 

    
    for (
int index 0index lengthindex += 4
    { 
        
tmpByte = (m_PixelBuf[index 1] + m_PixelBuf[index 2] + m_PixelBuf[index 3]) / 3
        if (
tmpByte >= 128
            
m_PixelBuf[index 1] = m_PixelBuf[index 2] = m_PixelBuf[index 3] = 255
        else 
            
m_PixelBuf[index 1] = m_PixelBuf[index 2] = m_PixelBuf[index 3] = 0
        
    } 
    
    
    
    
ctx CGBitmapContextCreate(m_PixelBuf
                                
CGImageGetWidthinImage ), 
                                
CGImageGetHeightinImage ), 
                                
8
                                
CGImageGetBytesPerRowinImage ), 
                                
CGImageGetColorSpaceinImage ), 
                                
kCGImageAlphaPremultipliedFirst ); 
    
    
    
CGImageRef imageRef CGBitmapContextCreateImage (ctx); 
    
UIImagerawImage = [UIImage imageWithCGImage:imageRef]; 
    
    
CGContextRelease(ctx); 
    
    
image.image rawImage
      
CFRelease(m_DataRef);
    
CGImageRelease(imageRef);

So I presume some CGimageRefs aren't released properly so I'm trying to find out a way to optimize this code to release them.

I also have some of these filters tied to an UISlider, so this can be annoyingly slow in this way and can even cause the app to crash.

Can anyone help?
ykrsdn is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,178
Threads: 93,918
Posts: 402,141
Top Poster: BrianSlick (7,966)
Welcome to our newest member, HugoMSousa
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.