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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-03-2011, 03:19 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 39
TheFrenchGuy is on a distinguished road
Default Leak when using JSONValue

Hy,

I've a big problem with my app.

Instruments says that there is a leak at this line :

Code:
//On décode donneeExamen en string
	NSString * lesDonnees = [[NSString alloc] initWithBytes: [donneeExamen mutableBytes] length:[donneeExamen length] encoding:NSUTF8StringEncoding];
    
    //On tranforme lesDonnees au format JSON
	NSDictionary * jsonResults = [lesDonnees JSONValue];

I don't know how to solve it.

Someone can help me ??

Thank you in advance
TheFrenchGuy is offline   Reply With Quote
Old 11-03-2011, 03:23 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Do you ever release lesDonnees?
harrytheshark is offline   Reply With Quote
Old 11-03-2011, 04:08 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 39
TheFrenchGuy is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
Do you ever release lesDonnees?
yes :

Code:
[donneeExamen release], donneeExamen = nil;
	[lesDonnees release],lesDonnees = nil;

I'm using NSURLConnection
TheFrenchGuy is offline   Reply With Quote
Old 11-04-2011, 12:42 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

You would need to show us more code.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 11-05-2011, 09:54 AM   #5 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 39
TheFrenchGuy is on a distinguished road
Default

Quote:
Originally Posted by dljeffery View Post
You would need to show us more code.
Here there is screen shoots to show you :



and :




32Kb of memory leak, it is very big !!
TheFrenchGuy is offline   Reply With Quote
Old 11-05-2011, 11:23 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Looks like a leak in the parser - switch to a better one. JSONKit is the best.
harrytheshark is offline   Reply With Quote
Old 11-05-2011, 02:45 PM   #7 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 39
TheFrenchGuy is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
Looks like a leak in the parser - switch to a better one. JSONKit is the best.
Ok thank you, but how to transfrom :

NSDictionary * jsonResults = [lesDonnees JSONValue]; ???


Thank You
TheFrenchGuy is offline   Reply With Quote
Old 11-05-2011, 03:24 PM   #8 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 39
TheFrenchGuy is on a distinguished road
Default

Quote:
Originally Posted by TheFrenchGuy View Post
Ok thank you, but how to transfrom :

NSDictionary * jsonResults = [lesDonnees JSONValue]; ???


Thank You
I'm doing like this but there a leak again of 20Kb, not the first time time but always after

Code:
NSString * lesDonnees = [[NSString alloc] initWithBytes: [donneeExamen mutableBytes] length:[donneeExamen length] encoding:NSUTF8StringEncoding];
    
    NSDictionary * jsonResults = [lesDonnees objectFromJSONString];

Last edited by TheFrenchGuy; 11-05-2011 at 03:54 PM.
TheFrenchGuy is offline   Reply With Quote
Old 11-05-2011, 09:57 PM   #9 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

You actually still didn't show enough code. Enough code would be to see where lesDonnees is allocated, and also where it is released.

You only showed where it's released in your screenshot... so there is still not enough context to go by.

EDIT: Also, pasting code into your post would be preferable to screen shots!
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 11-06-2011, 04:57 AM   #10 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 39
TheFrenchGuy is on a distinguished road
Default

Ok,

Code:
// Starts a connection to download the current URL.
- (void)_startReceive
{
    NSURL * url;
    NSURLRequest * request;
        
    app_Delegate.email=[[NSUserDefaults standardUserDefaults] objectForKey:@"emailKey"];
    
    app_Delegate.idScore=[[NSUserDefaults standardUserDefaults] valueForKey:@"IDC2i"];
    
    if ( (app_Delegate.email==nil) || [app_Delegate.email isEqualToString:@""]) //Envoi d'un requête HTTP sans email
    {
        //création de l'url
        NSString * tmp = [NSString stringWithFormat:@"%@%@",app_Delegate.plateforme,app_Delegate.getAnonyme];
        url = [NSURL URLWithString: tmp];
        //création de la requête
        request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
        assert(request!=nil);
        if (connexion) 
        {
            [connexion release], connexion = nil;
        }
        connexion = [NSURLConnection connectionWithRequest:request delegate:self];
        assert(connexion!=nil);

    }
    else if (app_Delegate.email !=nil || ![app_Delegate.email isEqualToString:@""])//Envoi d'une requête HTPP avec email
    {
        //création de l'url
        NSString * tmp = [NSString stringWithFormat:@"%@%@&email=%@",app_Delegate.plateforme,app_Delegate.getAnonyme,app_Delegate.email];
        url = [NSURL URLWithString: tmp];
        //création de la requête
        request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
        assert(request!=nil);
        
        if (connexion) 
        {
            [connexion release], connexion = nil;
        }
        connexion = [NSURLConnection connectionWithRequest:request delegate:self];
        assert(connexion!=nil);
    }    

    
    //Tell the UI we're receiving
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    connectingAlert = [[WheelAlertView alloc]   initWithTitle:NSLocalizedString(@"connexion", @"") 
                                                            message:@"" 
                                                            delegate:nil 
                                                            cancelButtonTitle:nil
                                                            otherButtonTitles:nil];
    [connectingAlert addWheel];
	[connectingAlert show];
    if (donneeExamen) 
    {
        [donneeExamen release], donneeExamen = nil;
    }
    donneeExamen = [[NSMutableData data] retain];
}

// Shuts down the connection and displays the result (statusString == nil) 
// or the error status (otherwise).
//méthode qui se lance si auncune connexion
- (void)_stopReceiveWithStatus:(NSString *)statusString
{
    //on stoppe la connexion
	if (connexion != nil) {
        [connexion cancel];
        connexion = nil;
    } 
        
    //on stop l'indicateur d'activité reseau
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    
    //on ferme le wheelAlertView
    [connectingAlert close];
    
    UIAlertView * alerte=[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"error", @"") message:statusString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alerte show];
    [alerte release];
    
}

// A delegate method called by the NSURLConnection when the request/response 
// exchange is complete.  We look at the response to check that the HTTP 
// status code is 2xx and that the Content-Type is acceptable.  If these checks 
// fail, we give up on the transfer.
- (void)connection:(NSURLConnection *)theConnection didReceiveResponse:(NSURLResponse *)response
{
#pragma unused(theConnection)
    NSHTTPURLResponse * httpResponse;
    NSString *          contentTypeHeader;
	
    assert(theConnection == self.connexion);
    
    httpResponse = (NSHTTPURLResponse *) response;
    assert( [httpResponse isKindOfClass:[NSHTTPURLResponse class]] );
    
    
    if ((httpResponse.statusCode / 100) != 2) {
        [self _stopReceiveWithStatus:[NSString stringWithFormat:@"erreur HTTP %zd", (ssize_t) httpResponse.statusCode]];
    } 
    else 
    {
        contentTypeHeader = [httpResponse.allHeaderFields objectForKey:@"Content-Type"];
		NSString * regex = @"(text/html)|(text/xml)";
        if (contentTypeHeader == nil) 
        {
            [self _stopReceiveWithStatus:@"Mauvais type de contenu"];
        } 
        else if ( ![contentTypeHeader isMatchedByRegex:regex] ) 
        {
			[self _stopReceiveWithStatus:[NSString stringWithFormat:@"Type de contenu non supporté (%@)", contentTypeHeader]];
        } 
        else 
        {
            [connectingAlert setTitle:NSLocalizedString(@"connexionEffectuee", @"")];
			/*donneeExamen = [[NSMutableData alloc] init];
			donneeExamen = [[NSMutableData data] retain];*/
            [donneeExamen setLength:0];
        }
    }    
}


// A delegate method called by the NSURLConnection as data arrives.  We just 
// write the data to the file.
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data
{
#pragma unused(theConnection)
    assert(theConnection == connexion);
	[donneeExamen appendData:data];//A ce moment donneeExamen ne contient que des bits
	[connectingAlert setTitle:NSLocalizedString(@"Reception de l'examen",@"")];
}



// A delegate method called by the NSURLConnection if the connection fails. 
// We shut down the connection and display the failure.  Production quality code 
// would either display or log the actual error
- (void)connection:(NSURLConnection *)theConnection didFailWithError:(NSError *)error
{
#pragma unused(theConnection)
#pragma unused(error)
    assert(theConnection == connexion);
    [self _stopReceiveWithStatus:[NSString stringWithFormat:@"%@",[error localizedDescription]]];
}



// A delegate method called by the NSURLConnection when the connection has been 
// done successfully.  We shut down the connection with a nil status, which 
// causes the image to be displayed.
- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection
{
#pragma unused(theConnection)
    assert(theConnection == self.connexion);
    
    //on annule la connexion
	if (connexion != nil) {
        [connexion cancel];
        connexion = nil;
    } 
    //on arrete l'indicateur d'activité réseau
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
	
    //On décode donneeExamen en string
	NSString * lesDonnees = [[NSString alloc] initWithBytes: [donneeExamen mutableBytes] length:[donneeExamen length] encoding:NSUTF8StringEncoding];
    
    //On ferme le wheelAlertView
	[connectingAlert close];
    
    //On tranforme lesDonnees au format JSON

	NSDictionary * jsonResults = [lesDonnees JSONValue];
   
    if ([[jsonResults objectForKey:@"error"] isEqualToString:@"Pas d'examen anonyme autorisé ou en cours"]) 
    {
        UIAlertView *actionSheet = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"PasDePositionnementAnonyme",@"")  message:NSLocalizedString(@"PasDePositionnementAnonymeMessage",@"")delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
		[actionSheet show]; 
		[actionSheet release];
        [lesDonnees release],lesDonnees = nil;
        [donneeExamen release], donneeExamen = nil;

        return;
    }
	if (jsonResults == nil) //Si jsonResults ne contient rien, on affiche une erreur
    {
		UIAlertView *actionSheet = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Problème de récupération des données",@"")  message:NSLocalizedString(@"mauvaise réception de l'examen",@"")delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
		[actionSheet show]; 
		[actionSheet release];
	} 
    else //sinon on peut lancer l'examen 
    {
		[app_Delegate lancementExamen:jsonResults];
	}

    [donneeExamen release], donneeExamen = nil;
	[lesDonnees release],lesDonnees = nil;
}

In the appDelegate :


Code:
- (void) lancementExamen:(NSDictionary *) data
{    
	dataAppDelegate=[data retain];
    [self.window.superview removeFromSuperview];
    [self.tabBarController.view removeFromSuperview];
	
	//on alloue une vue de type ExamenViewController qui est en faite une UITableVIewController
    if (examenViewController) 
    {
        [examenViewController release], examenViewController = nil;
    }
        examenViewController = [[ExamenViewController alloc]  initWithInterface];
  
    [examenViewController UpDateData:dataAppDelegate];
	
    //on alloue un UINavigationController avec comme root : exameView
	UINavigationController * tmpNavigationController = [[UINavigationController alloc] initWithRootViewController:examenViewController];
	navigationController = [tmpNavigationController retain];
    
    self.navigationController.toolbarHidden=NO;
    self.navigationController.toolbar.barStyle=UIBarStyleBlack;
    
    [self.window addSubview:[navigationController view]];
    [tmpNavigationController release];

}

If you want to see more code, tell me.

Thank you for your help
TheFrenchGuy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 419
17 members and 402 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, n00b, pbart, reficul, Retouchable, Sami Gh, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:18 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0