Memory leaks
- Get link
- X
- Other Apps
hi all,
- (uitableviewcell *)tableviewuitableview *)tableview cellforrowatindexpath
nsindexpath *)indexpath
{
nsstring *myidentifier = @"myidentifier";
uitableviewcell *cell = (uitableviewcell *)[tableview dequeuereusablecellwithidentifier:myidentifier];
if (cell == nil)
{
cell = [[[uitableviewcell alloc] initwithframe:cgrectzero reuseidentifier:myidentifier]autorelease];
}
//uitableviewcell *cell = [[uitableviewcell alloc]init];
itemobject = nil;
itemobject = [menuobject.menuitemsarray objectatindex:indexpath.row];
cell.text = itemobject.itemname;
cell.font = [uifont systemfontofsize:13.0];
cell.textcolor = [uicolor blackcolor];
cell.textalignment = uitextalignmentleft;
if(itemobject.iimg != nil)
{
if([[itemobject.iimg substringtoindex:4] isequaltostring"http"])
{
//nsautoreleasepool *poolobj = [[nsautoreleasepool alloc]init];
nsurl *urlstring = [[nsurl alloc]initwithstring:itemobject.iimg];
nsdata *data = [[nsdata alloc]initwithcontentsofurl:urlstring];
uiimage *img = [[uiimage alloc]initwithdata:data];
cell.image = img; //[uiimage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:itemobject.iimg]]];
img = nil;
data = nil;
urlstring = nil;
itemobject = nil;
//[poolobj drain];
}
else
{
cell.image = [uiimage imagenamed:itemobject.iimg];
}
state = 1;
}
//[itemobject release];
return cell;
}
when run app,i see leaks in instruments , when trace stack go line.
nsdata *data = [[nsdata alloc]initwithcontentsofurl:urlstring];
not able find out why.so please me.
not here,i parsong xml files using nsxmlparser object,it show me leaks @ line also
nsxmlparser *parser = [[nsxmlparser alloc] initwithcontentsofurl:url];
relesing parser object.
- (void)parsexmlfileaturlnsurl *)url parseerror
nserror **)error
{
//[self parsexmlfileatdata:[nsdata datawithcontentsofurl:url options:1 error:error]];
nsxmlparser *parser = [[nsxmlparser alloc] initwithcontentsofurl:url];
// set self delegate of parser receive parser delegate methods callbacks.
[parser setdelegate:self];
// depending on xml document you're parsing, may want enable these features of nsxmlparser.
[parser setshouldprocessnamespaces:no];
[parser setshouldreportnamespaceprefixes:no];
[parser setshouldresolveexternalentities:no];
[parser parse];
nserror *parseerror = [parser parsererror];
if (parseerror && error)
{
*error = parseerror;
}
[parser release];
}
you don't release object allocated using alloc. you've done set references nil, doesn't here. lose reference object it's still there eating memory.
every alloc message should have corresponding release message after you're done object.
read guide: memory management programming guide cocoa
edit: see it's iphone code. above guide still applies.
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
- Get link
- X
- Other Apps
uitableview *)tableview cellforrowatindexpath
Comments
Post a Comment