2011-12-17 26 views
1

我在这个应用程序中有3个类。继承类中的内存泄漏与SQLite3和NSDictionary?

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

我混淆了NSDictionary,NSString和Sqlite?

泄漏发生在这一行!!!?

NSDictionary * brandRow = [fairPrice_DB getProductRow:tempProductID];

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

brandRow = nil;

我刚刚开始在iPhone应用程序,我提前感谢任何帮助,我已经阅读了许多iPhone内存管理指南,但我无法解决它。问题是我没有使用任何关键字看起来像分配,保留,复制或mutablecopy,但我有泄漏在这一行!

此行带回一个包含productID,productName,brandName,price的NSDictionary。从包装类,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; 
    } 
} 

回答

0

问题是通过重写dealloc方法解决:d

DetailBrands.m

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

我总是把'dealloc'方法在'm'文件的顶部,在'@ synthesize'语句的正下方。然后,记住保持它是最新的,并且在记住时更容易找到并更新它会更容易。 – 2011-12-20 04:29:17

+0

你好,这是通过最小化错误的好解决方案..这是我的第一个iPhone应用程序:D .. – Danial 2011-12-22 08:42:40