Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-29-2009, 12:25 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Michigan
Posts: 30
tpurves is on a distinguished road
Default The following block of code bit me today

The following block of code bit me today.

Thinking about it.... I understand why... I broke the golden rule of memory management with objective-C (e.g., if you didn't alloc it or retain it, then you don't release it). The bug is in the fact with the code that is broken, the allocated object passed to lowercaseString is lost when lowercaseString creates a new string with autorelease, and then later in the code I released an object that I didn't allocate or retain.

I hope this helps someone.

Code:
// this code is broken
-(NSString*)getCodeForCharacter:(unichar)ch
{
	NSString *key = [[[NSString alloc] initWithCharacters:&ch length:1] lowercaseString];
	NSString *value = [code valueForKey:key];
	[key release];
	return value;
}
Code:
// this code is correct
-(NSString*)getCodeForCharacter:(unichar)ch
{
	NSString *key = [[NSString alloc] initWithCharacters:&ch length:1];
	NSString *value = [code valueForKey:[key lowercaseString]];
	[key release];
	return value;
}
tpurves is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 462
12 members and 450 guests
Domele, Duncan C, Feldspar, MacBook MH, Objective Zero, patapple, peterwilli, pipposanta, Punkjumper, SLIC, taylor202, Today's Posts
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,694
Threads: 94,137
Posts: 402,950
Top Poster: BrianSlick (7,990)
Welcome to our newest member, peterwilli
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0