我在此应用程序中有3个班级。
在DetailBrand2.m中发生内存泄漏,
从DetailType继承的DetailBrand2,
我也有一个包装类FairPriceDatabaseView,它与sqlite3进行通信。
我对NSDictionary,NSString和Sqlite感到困惑吗?
该行发生泄漏了!!?
NSDictionary * brandRow = [fairPrice_DB getProductRow:tempProductID];
NSString * message = [brandRow objectForKey:@“ brandName”];
brandRow = nil;
我刚刚开始从事iPhone应用程序开发工作,在此先感谢您的帮助,我已经阅读了许多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;
}
}
最佳答案
该问题通过覆盖dealloc方法解决:D
DetailBrands.m
-(void) dealloc
{
[self.tempProductID release];
[self.topBrandName release];
[self.brandName release];
[super dealloc];
}