Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to set NavDialogCreationOptions strings



On 30 Jul 2004, at 02:05, Scott Thompson wrote:
Why isn't that a memory leak?

Well it's not a memory leak if you don't own those strings.

It could, potentially, be a memory leak, but there's no way for you to
know.

I strongly suspect, however, that it is not.

At the very least, the operating system is probably expecting to use
the same strings every time you create default dialog options. If you
were to free those strings out from under the Navigation Services
framework, that would be a Bad Thing

If I had to guess at how Navigation services is implemented, however, I
would say that you couldn't really "free" those strings even if you
tried. The operating system is probably creating a CFString from a
static string somewhere using the same technology that sits behind the
CFSTR macro. With such objects you can pretty much think of the string
as being created at compile-time and stored in the program's global
data.

Well it's more likely to be a CFCopyLocalizedString type thing.
As I understand, these strings can actually participate in
retain-release semantics. Since the memory can't actually be freed,
however, releasing them enough that they should be freed is actually
an unsupported operation with undefined behavior (at least according to
engineers at Apple).

I seem to recall that conceptually CFSTR(foo) actually calls through to cfstringcreatewithcstring (cacheing results of course), although that is of course an implementation detail that may have changed, i note that gcc has an fconstant-cfstrings switch. Whatever they are, they do behave as you would expect any cftype to: releaseing them more times than you have retained/copied/created them is definitely bad mojo.

Anyway, i got bored and had a quick look, as i had guessed earlier, all the strings are set to NULL, so there's no leaking whatever you do.

Fred

The thing to keep in mind here, however, is that you didn't allocate
those strings so you are not responsible for releasing them. If it is
a memory leak... it's the OSes fault and not yours.

--
Macintosh Software Engineering Consulting Services
Visit my resume at <http://homepage.mac.com/easco/RSTResume.html>

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: how to set NavDialogCreationOptions strings (From: Kurt Bigler <email@hidden>)
 >Re: how to set NavDialogCreationOptions strings (From: Frederick Cheung <email@hidden>)
 >Re: how to set NavDialogCreationOptions strings (From: Scott Thompson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.