discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gworkspace - ddbd connection problems


From: Fred Kiefer
Subject: Re: gworkspace - ddbd connection problems
Date: Thu, 21 Feb 2013 09:08:09 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2

On 20.02.2013 01:34, Riccardo Mottola wrote:
While I experimented with removing certain autoreleasepools around
connections, as tit was suggested here on the list, without results,
Sebastian empirically fount out that this aptch

Index: Tools/ddbd/ddbd.m
===================================================================
--- Tools/ddbd/ddbd.m   (revision 36176)
+++ Tools/ddbd/ddbd.m   (working copy)
@@ -223,14 +223,12 @@

  - (NSArray *)userMetadataForPath:(NSString *)apath
  {
-  CREATE_AUTORELEASE_POOL(arp);
    NSArray *usrdata = nil;

    [pathslock lock];
    usrdata = [pathsManager metadataForPath: apath];
    [pathslock unlock];

-  RELEASE (arp);

    return usrdata;
  }


helps a lot, for example it does not crash on MDKit indexing.. But why?
I cannot see anything bad to instantiate a new autoreleasepool and
releasing it later. Why woul this change make connections die or not?

That is easy to explain. You get back an autoreleased array from metadataForPath:. As there is an autorelease pool around that code, this array will get released within the autorelease pool. Next you return that now invalid object from your method. The caller will may get an invalid pointer. This is the second basic memory management rule you have to learn when coding Objective-C (the first being to match release and retain calls), if you need to hold on to a variable retain it. I don't see why you would need an autorelease pool here, but if there is reason for it, you need to retain usrdata when assigning it and autorelease it in the return line.

Hope this helps,
Fred





reply via email to

[Prev in Thread] Current Thread [Next in Thread]