Re: MDItemCreate very, very, very, slow -- and fails
Re: MDItemCreate very, very, very, slow -- and fails
- Subject: Re: MDItemCreate very, very, very, slow -- and fails
- From: Kaelin Colclasure <email@hidden>
- Date: Tue, 14 Feb 2006 11:57:15 -0800
On Feb 14, 2006, at 11:36 AM, Doug Knowles wrote:
The code:
- (NSDictionary *)loadMetadata
{
NSDictionary *md;
NSString *path = [self valueForKey:@"uniqueIDValue"];
NSLog( @"Fetching metadata for %@", path );
MDItemRef mdi = MDItemCreate( nil, (CFStringRef)path );
if ( mdi != nil ) {
NSArray *attrNames = (NSArray *)MDItemCopyAttributeNames( mdi );
md = (NSDictionary *)MDItemCopyAttributes( mdi, (CFArrayRef)
attrNames );
CFRelease(mdi);
}
else {
md = [NSDictionary dictionary];
}
return md;
}
...and some clarifications:
- The code does work properly sometimes, then starts failing.
- I call this *a lot*; it's not inconceivable that I would invoke this
on hundreds of files, so a leak (most likely on my part) could be
trouble.
A couple of memory management points to consider:
- You're leaking the attrNames array each time this is called.
- The dictionary this method returns is sometimes autoreleased,
and sometimes not.
Both of these could account for eventual failures because of memory
exhaustion. I'd suggest cleaning these up and then trying again.
On a broader note, this code is making three round-trips to mds for
every item... IFF you can hoist the call to MDItemCopyAttributeNames
() (assuming that the items all have the same set of attributes), or
pre-compute a superset of all the attributes that any item my have
that you care about, you could cut the per-item overhead by 33%.
Better still, if you could formulate a query that returns all the
items you care about, and ask for the attributes with the query, you
can eliminate this loop altogether and get everything back in one
round-trip. (Of course neither of these optimizations may be
practical with your specific usage.)
HTH,
-- Kaelin
Thanks,
Doug K;
What you're describing would be consistent with the framework's MIG
call to mds timing out for some reason. It would be helpful if you
could post a short example snippet that demonstrates this problem. If
you can reproduce it, please file a Radar: <http://
bugreport.apple.com.>.
HTH,
-- Kaelin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden