Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 593323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:50:01+00:00 2026-05-13T15:50:01+00:00

I’m very new to Objective-C and I’m trying to develop an iPhone app. My

  • 0

I’m very new to Objective-C and I’m trying to develop an iPhone app. My problem is I get “message sent to deallocated instance 0x3d54830” error when I use an object inside an NSTimer. When I don’t use an NSTimer, I can use the object just fine. For example:

//These can be any objects.  Le't say I have a Song class and a SongReader class in the header file SongTest.h
Song *song;
SongReader *reader;

NSTimer *timer;

- (void)justDoIt;


//In the implementation file SongTest.m
- (void)viewDidLoad {
    reader = [[SongReader alloc] init];
    song = [reader readSong];

    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(justDoIt) userInfo:nil repeats:YES];
}

- (void)justDoIt {
    NSLog(@"This is a song integer property: %d", song.wordCount);
}

- (void)dealloc {
    [reader release];
    [super dealloc];
}

The song object inside the justDoIt method/selector/message is already deallocated according to the debugger. What am I doing wrong? Even if I do it like:

song = [[reader readSong] retain]; //or
[song retain]; //or
[reader retain];

The object still gets deallocated unexpectedly. Again, the problem only happens when I use NSTimer. It’s like the object gets deallocated even before the timer fires.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:50:02+00:00Added an answer on May 13, 2026 at 3:50 pm

    Are you retaining your SongTest object? You don’t show that part of the code, but if it’s autoreleased, it will be deallocated by the time the timer fires. In fact, that’s really what the error message is indicating:

    “message sent to deallocated instance 0x3d54830”

    You’re creating the timer to send a message to “self” which is the SongTest object.

    Also, you do need to retain the song:

    song = [[reader readSong] retain];
    

    if you’ve coded -readSong according to the standard Cocoa conventions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.