Application is hangs. Why?

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

  1. macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hi,
    This slider's control action function:
    Code:
    - (IBAction)dragSlider:(id)sender
    {
    	NSNumber *tmpValue = nil;
    	
    	if(_isChecked == YES)
    	{
    		// double value
    		tmpValue = [NSNumber numberWithInt: [ sender intValue ] *2 ];
    		[ _position setStringValue: [ tmpValue stringValue ] ];
    	}
    	else
    	{
    		tmpValue = [NSNumber numberWithInt: [ sender intValue ] ];
    		[ _position setStringValue: [ tmpValue stringValue ] ];
    	}
    	
    	// free resources
    	[tmpValue release];
    }
    
    
    Why does application is hang?

    Thanks.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Either retain the NSNumber, or remove the [tmpValue release] - it's not necessary since the object is autoreleased.
     
  3. thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #3
    You mean garbage collector is responsible for memory management?
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    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

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #6
    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

    Joined:
    Jan 3, 2009
    #7
  8. Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #8
    oh right... i knew that, i swear...
    :eek:
     

Share This Page