views:

47

answers:

1

When running my iPhone app code with memory leak tool it says that i have two memory leaks in this method. The first when calling cell.textLabel setText: and the second when calling cell.imageView setImage:

I can't figure out what it's wrong, please can you help me?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"IssuesCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    // The issue object
    Issue *issue;
    issue = [issues objectAtIndexPath:indexPath];

    // Issue name
    [cell.textLabel setText:[issue name]];

    // Get a string from the issue date
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [cell.detailTextLabel setText:[dateFormatter stringFromDate:[issue date]]];
    [dateFormatter release];
    [cell.imageView setImage:[UIImage imageNamed:[issue cover]]];

    return cell;
}

Issue definition:

#import <CoreData/CoreData.h>

@class Article;

@interface Issue :  NSManagedObject  
{
}

@property (nonatomic, retain) NSString * cover;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSSet* articles;

@end


@interface Issue (CoreDataGeneratedAccessors)
- (void)addArticlesObject:(Article *)value;
- (void)removeArticlesObject:(Article *)value;
- (void)addArticles:(NSSet *)value;
- (void)removeArticles:(NSSet *)value;

@end

And implementation

#import "Issue.h"

#import "Article.h"

@implementation Issue 

@dynamic cover;
@dynamic name;
@dynamic date;
@dynamic articles;

@end
A: 

Given that both identified lines contain calls to methods of 'issue' and, as everyone else has already pointed out, there are no obvious leaks within your posted code, it stands to reason there may be something wrong with those two methods since your code assumes that they either don't return objects with a reference you have to release.

imaginaryboy
Hi imaginaryboy, thanks for your answer. The strange thing is that the leak is discovered also if i pass a static NSString to setText:For example[cell.textLabel setText:@"foo"];still causes a leak
Paolo Sangregorio
No i'm sorry, it doesn't happen if i put a static NSString. Well, i've added the 'issue' definition at the post on the top
Paolo Sangregorio
How are the 'name' and 'cover' properties implemented? Via a simple @synthesize? Or are you writing your own getter methods?
imaginaryboy
They are implemented as @dynamic (they were auto generated from a xcdatamodel file) Added to the post on top
Paolo Sangregorio
Extremely puzzling indeed. If you're using unaltered auto-generated model classes then they certainly should not be leaking, and certainly don't in the quick test app I just tried.
imaginaryboy
Thank you for your help imaginaryboy, i really appreciate it. After another analysis i found that there are two other leaks, all depending on "open_handle_to_dylib_path" and they are not related to my code (in the stack on the right there are no references to my source code). Could be a related issue?
Paolo Sangregorio