objective-c - BlogEntry 上的内存泄漏在哪里?

标签 objective-c ios cocoa-touch memory-leaks

我正在分析 iPhone 的 iOS 4 应用程序,并得到以下日志:

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

你知道我的内存泄漏在哪里吗?我找不到它。

最佳答案

您应该看看静态分析器。它会告诉你出了什么问题。

请参阅本文档中的查找编码错误部分: http://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/Debugging/Debugging.html

...或者自己尝试一下:在 XCode 中按 Product > Analytics

关于objective-c - BlogEntry 上的内存泄漏在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9861256/

相关文章:

ios - AFNetworking POST 错误 3840

objective-c - 我正在使用 drawRect : how can I draw a button? 实现 UIView 子类

ios - 使 SKPhysicsBody 单向

iphone - UIView 转换导致崩溃

objective-c - Xcode 中的 EXC_BAD_ACCESS (code=1) 错误

IOS - 导入提要图像 - Retina 支持

iphone - 在 Objective C iPad App 中获取任何控件的绝对位置

iphone - 使用 SDWebImageDownloader 显示和隐藏 ActivityIndi​​cator

iOS 13 深色模式和启动屏幕 - iOS 10 的后备

iphone - 委托(delegate)是执行此操作的首选方法吗?