Leaks

adamfenn28's picture

@cwright informed my that my code was leaky in my previous thread. http://kineme.net/comment/reply/10277/20045

I still have a line like the following in -execute:

         [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

However, I'm trying to release everything in like follows:

- (void) dealloc
{
   /*
   Release any resources created in -init.
   */
   [response dealloc];
   [super dealloc];
}
 
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
   responseData = [[NSMutableData alloc] init];
}
 
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
   [responseData appendData:data];
}
 
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
   [connection release];
   failWithError = TRUE;
 
}
 
- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
  response = [[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding];
   [responseData release];
   [connection release];
   failWithError = FALSE;
 
 
}

Outside of this bit, I've released all objects I created with alloc. I didn't create any with copy. All my ivars are synthesized properties and response and responseData both get released in the code above. Everything else is a BOOL.

I thought this covered it, but when I run my completed composition under Leaks, I can see leaks and leaked bytes incrementing. From the look of the data provided by Leaks, I can't tell if it's my code that's leaking or if it's something else in QC.

Does it sound like I've done ok with preventing leaks, or is there more work to do?

Thanks!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
Re: Leaks

your dealloc is totally wrong. absolutely do not call -dealloc on anything other than super. call -release on things you're no longer using. (so that "[response dealloc]" call -- totally bad idea).

look into using MallocStackLogging, guard malloc, and Instruments to identify what's leaking, where it's allocated, and who's responsible (unfortunately, QC leaks sometimes, mostly in the editor).

adamfenn28's picture
Re: Leaks

@cwright Thanks! I'm not sure why I dealloc'd release. I knew I wanted to release it.

I'll look at those tools if it still appears to be leaking.