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

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
I have some code that is giving me trouble.

Apparently Instruments tells me that there is a leak in the string:
PHP:
aNum = round([aSlider value]);
NSString *aString = [[NSString alloc] initWithFormat:@"%1.2f", round(aNum)];
[aText setText:aString];
[aString release];

(aNum, aSlider and aText are properties of the class)
What I do not get is how aString is leaking!
 

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
It is a NCSFString, it is 16 bytes, and it has trouble with the line:
PHP:
[aText setText:[NSString stringWithFormat:@"%1.2f", aNum]];

Beats me!
 

SilentPanda

Moderator emeritus
Oct 8, 2002
9,992
31
The Bamboo Forest
Admittedly I've only still working my way through Objective-C learning (100 more pages!) so I might not have the best insight but...

Are you releasing aText during your dealloc?

Actually I guess you might need to release it in places other than the dealloc... but yeah maybe check that?
 

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
Yep, in all my classes, all my retained properties are released in the dealloc.
 

drivefast

macrumors regular
Mar 13, 2008
128
0
Code:
aNum = [B]round[/B]([aSlider value]);
NSString *aString = [[NSString alloc] initWithFormat:@"%1.2f", [B]round[/B](aNum)];
try fixing this first. you may not need round at all, since the printf format will round for you.
 

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
Got that leak .. but found another interesting one in a drawRect function:

PHP:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
[fillColor setFill];
CGContextFillEllipseInRect(context, rect);
 

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
By changing it to:
PHP:
aNum = [aSlider value];
aNum = round(aNum);

and by getting rid of the second round() call.
 

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
By the way, is it possible to use Instruments to analyze how the program runs on the phone? There seems to be a problem with the phone because it doesn't have the processing power, and I need Instruments to be able to determine what the process is and how I can stop it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.