Potential leak of an object allocated on line 576
-(void)setMedicineList:(NSString*)btnText:(NSString*)kana:(NSString*)skana
{
if(mdcnList != nil)
{
[md开发者_JAVA技巧cnList release];
}
mdcnList = [[MedicineList alloc]getMedicineList:btnText:kana:skana]; // Memeory leak
[medListView setMdcnList:mdcnList];
[btnText release];
//[mdcnList release]; // Not work
}
How to release mdcnList to avoid "Potential leak of an object allocated on line 576" warning ? "getMedicineList" is another function. MedicineList is Class.
I'm not sure what your "// Not work" means - you mean the [mdcnList release] causes a problem?
Assuming so, that line should be uncommented. The problem may well be [medListView setMdcnList:] is not retaining a reference to mdcnList, when it should be.
I assume mdcnList
is a property. If it's defined as retain
, you should use the accessor, instead of releasing the iVar, and setting it manually...
Replace
if(mdcnList != nil) { [mdcnList release]; }
mdcnList = [[MedicineList alloc]getMedicineList:btnText:kana:skana];
By something like:
self.mdcnList = [ [ [ MedicineList alloc ] getMedicineList: btnText: kana: skana ] autorelease ];
As you can see, we are auto-releasing the object, as it will be automatically retained by the accessor.
精彩评论