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

  • Home
  • SEARCH
  • 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 8229837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:56:00+00:00 2026-06-07T16:56:00+00:00

I have an issue where I can’t seem to dealloc UIDocument (used in iCloud)

  • 0

I have an issue where I can’t seem to dealloc UIDocument (used in iCloud)

After running an NSMetaDataQuery to look for the document as follows..

NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
_query = query;
[query setSearchScopes:[NSArray arrayWithObject:
                        NSMetadataQueryUbiquitousDocumentsScope]];
NSPredicate *pred = [NSPredicate predicateWithFormat: 
                     @"%K == %@", NSMetadataItemFSNameKey, kFILENAME];
[query setPredicate:pred];
[[NSNotificationCenter defaultCenter] 
 addObserver:self 
 selector:@selector(queryDidFinishGathering:) 
 name:NSMetadataQueryDidFinishGatheringNotification 
 object:query];

[query startQuery];

I process my query

- (void)queryDidFinishGathering:(NSNotification *)notification {

NSMetadataQuery *query = [notification object];
[query disableUpdates];
[query stopQuery];

[[NSNotificationCenter defaultCenter] removeObserver:self 
                                                name:NSMetadataQueryDidFinishGatheringNotification
                                              object:query];

_query = nil;

[self loadData:query];

}

Then load or create a new document.

- (void)loadData:(NSMetadataQuery *)query {

if ([query resultCount] == 1) {

    NSMetadataItem *item = [query resultAtIndex:0];
    NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
    MyDocument *doc = [[[MyDocument alloc] initWithFileURL:url] autorelease];

    [doc openWithCompletionHandler:^(BOOL success) {
        if (success) {                
            NSLog(@"iCloud document opened %@", doc);
            [doc updateChangeCount:UIDocumentChangeDone];
        } else {                
            NSLog(@"failed opening document from iCloud");                
        }
    }];
} else {

    NSURL *ubiq = [[NSFileManager defaultManager] 
                   URLForUbiquityContainerIdentifier:nil];
    NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:
                                 @"Documents"] URLByAppendingPathComponent:kFILENAME];

    MyDocument *doc = [[[MyDocument alloc] initWithFileURL:ubiquitousPackage] autorelease];

    [doc saveToURL:[doc fileURL] 
  forSaveOperation:UIDocumentSaveForCreating 
 completionHandler:^(BOOL success) {            
     if (success) {
         [doc openWithCompletionHandler:^(BOOL success) {                
             NSLog(@"new document opened from iCloud");
             [doc updateChangeCount:UIDocumentChangeDone];
         }];                
     }
 }];
}
}

The NSLog(@"iCloud document opened %@", doc); shows a different memory address for each UIDocument.

I have an NSLog in my UIDocument subclass, it never gets called. I cannot see where it is being retained that I am not releasing it. This query is ran whenever I want to sync my cloud data, this happens fairly regularly. The data syncs correctly.

I am experiencing strange crashes where my app will simply close to the dashboard, with nothing in the debug (from previous experiences I know this often to be the app expending too much memory and being terminated.)

I think that my UIDocument is leaking, would I be correct in this assumption, this is the first time i’ve wrestled with iCloud so I’m still in the dark over a few things.

My subclass has the following properties:

@property (copy, nonatomic) NSData *infoData;
@property (copy, nonatomic) NSMutableArray *firstArray;
@property (copy, nonatomic) NSMutableArray *secondArray;
@property (copy, nonatomic) NSMutableArray *thirdArray;

I am not using ARC.

  • 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-06-07T16:56:03+00:00Added an answer on June 7, 2026 at 4:56 pm

    I did not realise that I had to do this:

            [doc updateChangeCount:UIDocumentChangeDone];
            [doc closeWithCompletionHandler:nil];
    

    Obviously if a file is open for writing, then it would not be wise to allow it to be deallocated!

    Doh! Hopefully this saves someone some time in the future.

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

Sidebar

Related Questions

I have a slight issue where I can't seem to select a User Control
I have an issue I can't seem to figure out... I have a widget
I have this issue that I can't seem to get my head around... Basically
I have an issue that I can't seem to solve. I am randomly generating
I have an issue and I can't seem to either find the answer here
I have an issue I can't seem to track down. I am using Flot
I have an issue in that a Symfony2 form can pass validation but still
I have this exact issue ASP.net can’t update page from event handler and it's
I have an issue that is driving me nuts and hoping someone can help.
I have an issue in regards the alignment of the marquee. You can see

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.