2012-03-25 101 views
0

我分析了iPhone的iOS 4的應用程序,我得到這個日誌:BlogEntry上的內存泄漏在哪裏?

Leaked Object # Address Size Responsible Library Responsible Frame 
BlogEntry,9 <multiple> 288 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a11700 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a33e30 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a44b80 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a47950 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a4b510 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a5e840 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a5e8c0 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a647c0 32 Bytes Paula -[BlogViewController dataReceived] 
BlogEntry,1 0x9a74ee0 32 Bytes Paula -[BlogViewController dataReceived] 

BlogViewController dataReceived方法,這是一個:

- (void) dataReceived 
{ 
    NSArray* data = [conn.parsedData objectForKey:kRootKey]; 

    blogEntries = [[NSMutableArray alloc] initWithCapacity:data.count]; 

    NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
    [df setDateFormat:@"yyyy-MM-dd"]; 
    NSTimeZone *timezone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
    [df setTimeZone:timezone]; 

    for (int i = 0; i < data.count; i++) 
    { 
     NSDictionary* object = [data objectAtIndex:i]; 

     NSString* titulo = [object objectForKey:kTituloKey]; 
     NSString* texto = [object objectForKey:kTextoKey]; 
     NSDate* fecha = [df dateFromString: [object objectForKey:kFechaKey]]; 
     NSString* foto = [NSString stringWithFormat:@"%@%@", kPhotoURLPrefix, [object objectForKey:kFotoKey]]; 

     BlogEntry* blogE = [[BlogEntry alloc] initWithTitle:titulo 
                 text:texto 
                 date:fecha 
                 photo:foto]; 
     [blogEntries addObject:blogE]; 

     [blogE release]; 
    } 

    [df release]; 
    [blogList reloadData]; 

    loadingView.hidden = YES; 
} 

但我認爲這個問題是在BlogEntry類:

BlogEntry.h

@interface BlogEntry : NSObject 
{ 
    NSString* title; 
    NSString* text; 
    NSDate* date; 
    NSString* photo; 
} 

@property (nonatomic, readonly) NSString* title; 
@property (nonatomic, readonly) NSString* text; 
@property (nonatomic, readonly) NSString* photo; 
@property (nonatomic, readonly) NSDate* date; 

- (id)initWithTitle:(NSString*)titulo 
       text:(NSString*)texto 
       date:(NSDate*)fecha 
       photo:(NSString*)foto; 

@end 

BlogEntry.m

#import "BlogEntry.h" 

@implementation BlogEntry 

@synthesize title; 
@synthesize text; 
@synthesize date; 
@synthesize photo; 

- (id)initWithTitle:(NSString*)titulo 
       text:(NSString*)texto 
       date:(NSDate*)fecha 
       photo:(NSString*)foto 
{ 
    if (self = [super init]) 
    { 
     title = [titulo copy]; 
     text = [texto copy]; 
     date = [fecha retain]; 
     photo = [foto copy]; 
    } 
    return self; 
} 

- (void) dealloc 
{ 
    [title release]; 
    [text release]; 
    [date release]; 
    [photo release]; 

    [super dealloc]; 
} 

@end 

你知道哪裏是我的內存泄漏?我找不到它。

回答

0
blogEntries = [[NSMutableArray alloc] initWithCapacity:data.count]; 
+0

是啊!你很棒! – VansFannel 2012-03-25 15:39:26