how to handle the memory mangment in this case

Discussion in 'iOS Programming' started by arjit, May 19, 2009.

  1. arjit macrumors newbie

    Joined:
    Feb 20, 2009
    #1
    i have a function
    Code:
    Code:
    // this is the header 
    @interface MyClass
    {
        theclass * obj;
    }
    
    
    // this is the .m file 
    -(void) doSomething{
        obj=[[theclass alloc] init];
    }
    
    -(void)something{
        theclass=nil;
        obj=[[theclass alloc] init];
    }
    
    so in something function it is getting a bad memory error how do this ?
    i need to init the same object again and again ....
    how do i do that again ?
    any help
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    In your "something" method, you're assigning nil to the class itself rather than to your instance of the class ("obj").
     

Share This Page