Application is hangs. Why?

Discussion in 'Mac Programming' started by Sergio10, Apr 1, 2009.

  1. macrumors regular

    This slider's control action function:
    - (IBAction)dragSlider:(id)sender
    	NSNumber *tmpValue = nil;
    	if(_isChecked == YES)
    		// double value
    		tmpValue = [NSNumber numberWithInt: [ sender intValue ] *2 ];
    		[ _position setStringValue: [ tmpValue stringValue ] ];
    		tmpValue = [NSNumber numberWithInt: [ sender intValue ] ];
    		[ _position setStringValue: [ tmpValue stringValue ] ];
    	// free resources
    	[tmpValue release];
    Why does application is hang?

  2. Moderator emeritus


    Either retain the NSNumber, or remove the [tmpValue release] - it's not necessary since the object is autoreleased.
  3. macrumors regular

    You mean garbage collector is responsible for memory management?
  4. Moderator emeritus


    No, your tmpValue is an autoreleased object, which means it gets released automatically later on by the autorelease pool. If you're not familiar with this (very important) concept, you should read through this and the other articles on memory management.
  5. Guest


    how can you tell from this code if the NSNumber instance is being autoreleased? is it because NSNumber is part of the foundation framework?
  6. macrumors 68030


    Do you see 'alloc', 'copy', or 'new' anywhere in the name of the method used to create it? If not, treat it as autoreleased.
  7. macrumors 6502

  8. Guest


    oh right... i knew that, i swear...

Share This Page