Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When filtering / enumerating the objects that don't match the predicate are not released #17

Open
beloso opened this issue Dec 8, 2014 · 4 comments

Comments

@beloso
Copy link

beloso commented Dec 8, 2014

I am trying to enumerate a database finding only the values that match a given predicate.

Here is my code:

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF.names BEGINSWITH[cd] %@", searchText];
        @autoreleasepool {
            [self.datastore enumerateKeysAndObjectsBackward:NO
                                                     lazily:NO
                                              startingAtKey:nil
                                        filteredByPredicate:predicate
                                                  andPrefix:nil
                                                 usingBlock:^(LevelDBKey *key, id value, BOOL *stop){
                                                         [self.searchResults addObject:value];
                                                 }];
        }
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            [self.searchDisplayController.searchResultsTableView reloadData];
        }];

The thing is that while enumerating Objective-LevelDB keeps all values in memory, even the ones that don't match the predicate. Not even lazy evaluation solves the issue here.

Am I doing something wrong? Can something be done to improve on memory usage?

@beloso
Copy link
Author

beloso commented Dec 8, 2014

I have added an @autoreleasepool within your for loop in the enumeration method. It did improve the memory footprint, however I am not sure if the autoreleasepool is apliable there. I am no expert in memory handling.

@matehat
Copy link
Owner

matehat commented Jan 11, 2015

Thanks for reporting this, and sorry about the delay responding to your issue! I will investigate this in depth this week.

@hanishabsigh
Copy link

@tiagoveloso where did you add the @autoreleasepool? I tried adding it in a few places with no luck. @matehat did you ever get around to looking at this? Thanks guys!

@hanishabsigh
Copy link

just for more context, I'm using this from Swift and seeing tons of memory growth on both writes and reads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants