strange dangling ptr

Discussion in 'iOS Programming' started by chhoda, Feb 11, 2010.

  1. chhoda macrumors 6502

    Joined:
    Oct 25, 2008
    #1
    I have a class
    Code:
    @interface myclass {
    NSTimer *timer
    }
    @property(nonatomic, retain) NSTimer* timer;
    @end
    
    and synthesize etc.

    I have two timer variables one repeat yes and another repeat no.

    the problem is, "repeat Yes" timer crashes when trying to invalidate inside the function which the timer itself had fired.

    when i allocate, i see timer = 0x38Axt3 ... like this, valid address.

    but when trying to invalidate, the value is 0x5 or 0x3. what's wrong ?

    i have made sure everywhere that neither the timer is being released or twice invalidated, that has been proved by putting breakpoints at all invalidate method calls

    regards
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You should probably post your implementation code here as well.
     
  3. chhoda thread starter macrumors 6502

    Joined:
    Oct 25, 2008
    #3
    Code:
    @implementation
    -int
    {
        timer = [NSTimer timerWithDuration:0.2 delegate:self   selector:@selector(timerFired);
    timer1 = [NSTimer timerWithDuration:0.2 delegate:self selector:@selector(timer1Fired);
    }
    
    void timerFired
    {
      [timer invalidate]; // this does not have proper address (0x5)
      timer = nil;
      [timer1 invalidate]; // this has proper address
      timer1 = nil;
    }
    @end
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    How about posting the actual code? That's not even gonna compile.
     
  5. chhoda thread starter macrumors 6502

    Joined:
    Oct 25, 2008
    #5
    oops

    i realised, there was no problem with this part of the code, after running cunit tool and fixing some other memory leaks, it vanished . spoilt lot of time and peace.
     
  6. chhoda thread starter macrumors 6502

    Joined:
    Oct 25, 2008
    #6
    how to stop autoreleasing

    isn't there a way to stop autoreleasing altogather and may be check allocation failure ? that would probably a better way of finding exact point of bugs.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    I'm not sure how that's possible, given the code you've supplied us.

    To avoid autoreleasing, do your own retaining.
     
  8. chhoda thread starter macrumors 6502

    Joined:
    Oct 25, 2008
    #8
    thanks

    any code examples as such ? for own retaining ?
     
  9. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge

Share This Page