内存泄漏与继承类中的SQLite3和NSDictionary?

时间:2011-12-17 18:12:50

标签: iphone objective-c ios memory-leaks sqlite

我在这个应用程序中有3个类。

在DetailBrand2.m中发生了内存泄漏, DetailBrand2继承自DetailType, 我还有一个包装类FairPriceDatabaseView,它与sqlite3进行通信。

我对NSDictionary,NSString和Sqlite感到困惑?

泄漏发生在这条线上!!!?

NSDictionary * brandRow = [fairPrice_DB getProductRow:tempProductID];

NSString * message = [brandRow objectForKey:@“brandName”];

brandRow = nil;

我刚开始在iphone appmication中,我提前感谢任何帮助,我已经阅读了很多iphone内存管理指南,但我无法解决它。问题是我没有使用任何关键字看起来像alloc,retain,copy或mutablecopy但我在这行中有泄漏!!

此行带回一个NSDictionary,其中包含productID,productName,brandName,price。从包装类开始,fairPrice_DB是FairPriceDatabaseView的一个实例。

DetailBrand2.h

@interface DetailBrand2 : DetailType
{
    NSString * topBrandName;
    NSNumber * tempProductID;
    NSString * brandName;
}
@property (nonatomic, retain) NSString * topBrandName;
@property (nonatomic, retain) NSString * brandName;
@property (nonatomic, retain) NSNumber * tempProductID;

-(void) loadbrandName;

@end

DetailBrand2.m

#import "DetailBrand2.h"
#import "SeventhFairPriceAppDelegate.h"

@implementation DetailBrand2

@synthesize topBrandName,brandName,tempProductID;

-(void) loadbrandName
{
    if(!topBrandName)
    {
        [self loadDB];
        *NSDictionary * brandRow = [fairPrice_DB getProductRow:tempProductID];*
        NSString *message = [brandRow objectForKey:@"brandName"];
        brandRow = nil;
        self.topBrandName = message;
//        self.brandName =  self.topBrandName;
    }
}

1 个答案:

答案 0 :(得分:0)

通过覆盖dealloc方法解决问题:D

DetailBrands.m

 -(void) dealloc
    {
          [self.tempProductID release];
          [self.topBrandName release];
          [self.brandName release];
          [super dealloc];
    }