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 6896817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:05:29+00:00 2026-05-27T07:05:29+00:00

I’m trying to track down a freeze problem with an app I am developing.

  • 0

I’m trying to track down a freeze problem with an app I am developing. I may be in the deep end of the NSAutoreleasePool and am screwing things up.

The app is playing a midi file. If I comment out the “simRespondToFileNote” code below that uses an NSAutoreleasePool it doesn’t freeze. If I let the code run, it will freeze at seemingly random points The crash log/console output doesn’t seem to indicate where the issue is occurring.

Here is the program flow:

  1. I’m using the Bass midi lib (C lib); it plays the midi file in its own thread.

  2. When a midi event occurs, a callback is triggered and I wrap the midi event data in an NSDictionary and route it to the main thread so I can do UI updates and some other stuff.

Here is the code that does the routing:

- (void)forwardFileNoteIn:(int) note withVelocity: (int) velocity
{
int position = BASS_ChannelGetPosition(midiFileStream, BASS_POS_MIDI_TICK);
float percent = ((float)position / (float)totalTicks);
int ticksInLoop = outLoopTick - inLoopTick;

QWORD bytes=BASS_ChannelGetPosition(midiFileStream, BASS_POS_BYTE); // get position in bytes
double seconds=BASS_ChannelBytes2Seconds(midiFileStream, bytes); // translate to seconds
int timeStamp =seconds*1000; // translate to milliseconds

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDictionary *midiData = [NSDictionary dictionaryWithObjectsAndKeys:
                           @"fileNoteIn", @"eventType",
                          [NSNumber numberWithInt:note], @"note",
                          [NSNumber numberWithInt:velocity],@"velocity",
                          [NSNumber numberWithInt:timeStamp],@"timeStamp",
                          [NSNumber numberWithInt:position],@"position",
                          [NSNumber numberWithFloat:percent],@"percentPlayed",
                          [NSNumber numberWithInt:ticksInLoop],@"ticksInLoop",
                          nil];

[delegate performSelectorOnMainThread:@selector(midiFileEvent:)
                            withObject:midiData
                            waitUntilDone:NO];
[pool release];

}

  1. From the delegate a message is sent to another object using the NSDictionary instance as a param. That object either sends the NSDictionary instance immediately to another object or queues it to be sent after a short delay (using performSelector: afterDelay: ).

Is it possible that the NSAutoreleasePool is deleting the NSDictionary instance before the queued message is triggered? I am not draining the pool anywhere – should I be doing that?

- (void)simRespondToFileNote:(NSDictionary *)dictionary
{
int velocity = [[dictionary objectForKey:@"velocity"] intValue];

if (velocity == 0){
    // noteOff - send it through
    [delegate routeUserSimMidiEvent:dictionary];
} else {

    float totalPercentCorrect = [dataSource getUserCorrectPercent];

    int note = [[dictionary objectForKey:@"note"] intValue];

    if (totalPercentCorrect < _userAccuracy){

        float lateNoteOnTimeDelay =  (dataSource.postTimeHighAccuracy - (dataSource.postTimeHighAccuracy /4)) / 1000.;
        float lateNoteOffTimeDelay = lateNoteOnTimeDelay + .1; // revise

        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

        // create noteOff data w/ velocity == 0; timeStamp == 0;
        NSDictionary *midiData = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSNumber numberWithInt:note], @"note",
                                  [NSNumber numberWithInt:0],@"velocity",
                                  [NSNumber numberWithUnsignedInt:0],@"timeStamp",
                                  nil];

        [self performSelector:@selector(simLateResponseToFileNote:)  withObject:dictionary afterDelay: lateNoteOnTimeDelay];
        [self performSelector:@selector(simLateResponseToFileNote:)  withObject:midiData afterDelay: lateNoteOffTimeDelay];
        [pool release];

    } else {

        float lateNoteOnTimeDelay =  (dataSource.postTimeLowAccuracy + (dataSource.postTimeLowAccuracy /4)) / 1000.0;
        float lateNoteOffTimeDelay = lateNoteOnTimeDelay + .1; // revise
         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

        // create noteOff data w/ velocity == 0; timeStamp == 0;
        NSDictionary *midiData =[NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithInt:note], @"note",
                                 [NSNumber numberWithInt:0],@"velocity",
                                 nil];

        // queue late noteOn
        [self performSelector:@selector(simLateResponseToFileNote:)  withObject:dictionary afterDelay: lateNoteOnTimeDelay];
        // queue late noteOff
        [self performSelector:@selector(simLateResponseToFileNote:)  withObject:midiData afterDelay: lateNoteOffTimeDelay];
        [pool release];

    }
}

}

  • 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-27T07:05:29+00:00Added an answer on May 27, 2026 at 7:05 am

    Your creation of a temporary autorelease pool in simRespondToFileNote: isn’t very useful, but shouldn’t be a problem. Your call to performSelector:withObject:afterDelay: will retain dictionary until its called. If forwardFileNoteIn:withVelocity: is on a thread that doesn’t have an autorelease pool yet, you may have to create it, but generally you do that at the top of the method. If this thread already has a pool, there’s no reason to create on here.

    From your description, I would suspect that simLateResponseToFileNote: is blocking the main thread too long. I would look there for a bottleneck.

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

Sidebar

Related Questions

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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; 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'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.