[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gworkspace - ddbd connection problems
From: |
Riccardo Mottola |
Subject: |
Re: gworkspace - ddbd connection problems |
Date: |
Thu, 21 Feb 2013 10:45:17 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0 SeaMonkey/2.15.2 |
Hi Fred,
Fred Kiefer wrote:
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.
thanks. I know that, but I missed it in that contxt. I had a closer
look: it appears that all ddbd methods that return information for paths
have the structure
create arp;
get information thorugh the path manager
retain information
release arp
return the information autoreleased.
Except that method found by Sebastian. I suppose Enrico or whoever wrote
this was worried that some kind of recursion would bloat the autorelease
pool too much due to some kind of recursion when thedding the data
through the path manager. It can't be that the autorelease pool was
missing, or the autorelease of the return information would not work either.
I think I will fix the mtehod which lack that structure and for some
reason lack the extra retain and autorelease of the retain information.
However, probably, it makes only sense to do this if the information is
gotten through something recursive (like an array of information),
otherwise it is excessive optimization.
Riccardo