NSMetadataQuery - Just a warning.
NSMetadataQuery - Just a warning.
- Subject: NSMetadataQuery - Just a warning.
- From: Michael Monscheuer <email@hidden>
- Date: Sat, 29 Oct 2011 23:10:03 +0200
Hi,
I just had a hard time with NSMetadataQuery and would like to share
the results.
NSMetadataQuery leaks one MDQuery for each change of the predicate.
Even deallocation of a NSMetadataQuery does not free the MDQuery objects
that have been created internally to run the query.
Beyond the possibility of nasty crashes, this goes along with quite a
strange side effect:
You can place 128 searches within your app before NSMedataQuery class
will end up in no longer search for anything. Even newly created
instances of NSMedataQuery will not start searching for the first time
after this weird barrier has been reached.
You can simply reproduce this with Apple's spotlighter example.
For time saving reason, I replaced spotlighter's editable text field by
NSSearchField and toggled its cell to search immediately
(-setSendsSearchStringImmediately: set to YES).
Start to type in some search strings. After typing in 128 chars
spotlighter will ignore further requests.
System: 10.7.2 (Lion), have not tried with 10.6.x yet.
A workaround is to call -stopQuery on NSMetadataQuery, before a new
MDQuery will be created internally (change predicate, start searching)
and in -dealloc of NSMetadataQuery to get rid of a possible running
query that have not been explicitly stopped yet. I additionally placed a
stop when NSMetadataQueryDidFinishGatheringNotification is received.
Doing all this causes the underlying MDQuery to be freed when no longer
needed and before a new search will begin.
And this also magically removes the limit of 128 searches.
I am wondering if calling -stopQuery so often has any negative effect on
internal caching (AFAIK result items may be shared among queries).
Yes, I will place a bug report asap.
Greetings from Germany,
MiMo
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden