Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
Hi all..


I just want to ask some final question regarding the memory management in iPhone?


1. What is the leak in following line?
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	NSString *MyIdentifier = @"MyIdentifier";
    
  	UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
	if (cell == nil) 
	{
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier]autorelease];
	}
    


[COLOR="red"]cell.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]]];[/COLOR]

return cell;


I posted the same before also.. Still i didnt get any satisfactory reply...



2. When the following method get called?

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application

is it when app is over-shooting the memory allowed or when doing some illegal memory operations???
 

supertoto

macrumors newbie
Jul 29, 2008
14
0
Hi all..


I just want to ask some final question regarding the memory management in iPhone?


1. What is the leak in following line?
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	NSString *MyIdentifier = @"MyIdentifier";
    
  	UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
	if (cell == nil) 
	{
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier]autorelease];
	}
    


[COLOR="red"]cell.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]]];[/COLOR]

return cell;


I posted the same before also.. Still i didnt get any satisfactory reply...



2. When the following method get called?

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application

is it when app is over-shooting the memory allowed or when doing some illegal memory operations???


1. As my app goes, you need retain your UIImage object before you use it.

2. Acutally, according to the guide, it will be called, when the system memory is not enough, and you need to add your code to release some memory when received this message. It is invoked automatically by the system. So, nobody knows when it will be invoked...:cool:

Hope help.
 

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
1. As my app goes, you need retain your UIImage object before you use it.

2. Acutally, according to the guide, it will be called, when the system memory is not enough, and you need to add your code to release some memory when received this message. It is invoked automatically by the system. So, nobody knows when it will be invoked...:cool:

Hope help.

But the thing is that the method is invoking for me soem times..after a 20 min usage of app.... (Even i checked in Malloc-Debug and find its just taking a MAX of 3 MB in runtime...)
 

Luke Redpath

macrumors 6502a
Nov 9, 2007
733
6
Colchester, UK
I can't see what would be leaking - all of the objects on the right side of the assignment should be autoreleased objects. The UITableViewCell will retain the UIImage assigned using cell.image= so there should be no need for you to retain it.
 

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
I can't see what would be leaking - all of the objects on the right side of the assignment should be autoreleased objects. The UITableViewCell will retain the UIImage assigned using cell.image= so there should be no need for you to retain it.

Yeah... even i think ther is no need of "retain" which can cause more leak...

I am getting a "leak-peak" for this line in INSTRUMENTS tool...


I broke down the line into different , still i got leak for the line , where i alloc-initialize the "NSData"


The INSTRUMENTS showing "CFURLResponse".. etc..etc... in details of leak
 

ploppy

macrumors newbie
Jan 13, 2007
10
0
Yeah... even i think ther is no need of "retain" which can cause more leak...

I am getting a "leak-peak" for this line in INSTRUMENTS tool...


I broke down the line into different , still i got leak for the line , where i alloc-initialize the "NSData"


The INSTRUMENTS showing "CFURLResponse".. etc..etc... in details of leak

NSData dataWithContentsOfURL: is known to leak. You might want to load your images some other way.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.