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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:17+00:00 2026-05-25T22:26:17+00:00

I have a memory leak in my document based app. It launches fine, I

  • 0

I have a memory leak in my document based app. It launches fine, I can open or make a new document, but only one or two times, and then the app crashes.
I used analyzed tool in Xcode and there are no issues.

However, Instruments reveals the memory leak, but I can’t find where it lies in my code.
Using Objects Allocations, I can see my NSDocument subclass isn’t released when I close the document… I don’t really know if this is the intended behaviour.

Here is how I read and write the document :

-(NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
    NSMutableData *d = [NSMutableData data];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]
                                 initForWritingWithMutableData:d];
    [archiver encodeObject:[self machine]
                    forKey:IVPCodingKeyMachine];
    [archiver finishEncoding];
    [archiver release];
    if(outError) {
        *outError = [NSError errorWithDomain:NSOSStatusErrorDomain
                                        code:unimpErr
                                    userInfo:NULL];
    }
    return d;
}

-(BOOL)readFromData:(NSData *)data
             ofType:(NSString *)typeName
              error:(NSError **)outErro {
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
                                     initForReadingWithData:data];
    machine = [[unarchiver decodeObjectForKey:IVPCodingKeyMachine] retain];
    [machine setDelegate:self];
    [unarchiver finishDecoding];
    [unarchiver release];
    if(outError) {
        *outError = [NSError errorWithDomain:NSOSStatusErrorDomain
                                        code:unimpErr
                                    userInfo:NULL];
    }
    return YES;
}

The machine property is declared like so : @property(readonly) IVPMachine *machine; on the machine ivar and IVPMachine class conforms to NSCoding protocol. In case of new documents I have overridden -(id)initWithType:(NSString *)typeName error:(NSError **)outError; method, here the code I use :

-(id)initWithType:(NSString *)typeName error:(NSError **)outError {
    self = [super initWithType:typeName error:outError];
    if (self) {
        machine = [[IVPMachine alloc] initWithCreditAmount:2000];
        [machine setDelegate:self];
        [machine setGame:[[IVPGamesLibrary sharedInstance]
                           objectInGamesAtIndex:0]];
    }
    return self;
}

Finally in -(void)dealloc; method I release the machine ivar.

I can’t figure out where the bug lies.. Isn’t my document subclass instance supposed to be released when I close a document in my app ?

Any help is welcome. Thank you.

  • 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-25T22:26:17+00:00Added an answer on May 25, 2026 at 10:26 pm

    As a wild guess, did you implement -[IVPMachine setDelegate:] to retain the delegate? If so, don’t do that. Delegates should be weak references, i.e., non-retaining. You own the IVPMachine, so if it owns you back, that’s a circular ownership, and is what is keeping both the document and the IVPMachine alive.

    More practically, dig some more in Instruments. It can tell you not only that you have leaked something, but every retention and release that has happened to it. Look through that list to find the retention that is not balanced out.

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

Sidebar

Related Questions

I have a huge web app that is having issues with memory leak in
Our team is faced with slow but serious Javascript memory leak . We have
I have a memory leak problem that just can not understand! Watch this initialization
I have an .net app that seems to have a memory leak issue(s). The
Possible Duplicate: Possible memoryleak in ConcurrentBag? I have epic memory leak in my app.
I´m new in iPhone development and I have this memory leak. I´m using an
Is it ever acceptable to have a memory leak in your C or C++
I am using Borland Builder C++. I have a memory leak and I know
What memory leak detectors have people had a good experience with? Here is a
I have a problem with a memory leak in a .NET CF application. Using

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.