• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Methods returning const char*'s [or similar] - am I responsible for freeing the pointer or not?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Methods returning const char*'s [or similar] - am I responsible for freeing the pointer or not?


  • Subject: Methods returning const char*'s [or similar] - am I responsible for freeing the pointer or not?
  • From: Wade Tregaskis <email@hidden>
  • Date: Thu, 4 Mar 2004 20:20:44 +1100

I know this is probably a stupid question, but I've been using ObjC for so long I've forgotten what the conventions are in the C/C++ world. I also couldn't find any mention of this via google or this list's archives, which I thought somewhat strange. Nonetheless.

Basically I'm wondering whether I should be freeing const pointers returned by various system/library methods. In particular, I'm thinking that it'd be a pretty silly thing to return an internal storage buffer - whether const or not - in a situation where that buffer may be deallocated before external references to it are removed (e.g. in the case where the buffer refers to some property of an object like a UI element).

But my memory tells me that a const pointer implies you shouldn't free it, since it's "const" and not my responsibility to manage. But for the reason I've already stated that seems like a foolish and impossible demand to place on the developer, to try and synchronise external references to buffers with their life spans. It also seems to directly break many [most?] fundamental black-box design principles.

Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: Giving a NSToolbaritem a command key...?
  • Next by Date: Fwd: Lotus Notes from cocoa
  • Previous by thread: Re: CFRunLoopStop
  • Next by thread: Re: Methods returning const char*'s [or similar] - am I responsible for freeing the pointer or not?
  • Index(es):
    • Date
    • Thread