• 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
Re: CoreFoundation and CFDate functions - question on memory de-allocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreFoundation and CFDate functions - question on memory de-allocation


  • Subject: Re: CoreFoundation and CFDate functions - question on memory de-allocation
  • From: j o a r <email@hidden>
  • Date: Thu, 8 Jan 2004 08:22:45 +0100

Are you doing this with CF-functions for performance reasons? I'm
asking, since I'm sure it would be more convenient to do it using the
NS-classes, and perhaps easier to get the memory management right
(depends on your confidence with ObjC I guess).

In the example below I would assume that you have to free the aCFDate,
dateFormatter1 and dateStr variables - basically those that are created
using "*Create*" methods. Read the CF documentation if you are
uncertain, and use memory monitoring tools to verify that you got it
right.

j o a r

On 2004-01-08, at 07.47, Kent Behrends wrote:

> I have a question on the code fragment below. It does what I want,
> namely returning the current time in yyyy-mm-dd hh:mm:ss format, but
> it seems to have allocated memory to hold the converted date time
> string.
>
> Do I need to release this memory?
>
> The code is expected to run every 5 seconds or so in the background
> for as long as the systems is up.
>
>
> // Get current CFDate
> CFDateRef aCFDate = CFDateCreate(kCFAllocatorDefault,
> CFAbsoluteTimeGetCurrent());
>
> // Create a date formatter and set its format string
> CFDateFormatterRef dateFormatter1 = CFDateFormatterCreate(NULL, NULL,
> kCFDateFormatterShortStyle, kCFDateFormatterShortStyle);
> CFDateFormatterSetFormat(dateFormatter1, CFSTR("yyyy-MM-dd HH:mm:ss"));
> CFStringRef dateStr = CFDateFormatterCreateStringWithDate(NULL,
> dateFormatter1, aCFDate);
>
> // Copy formatted string into loopData struct
> strncpy(loopData->dateTime,CFStringGetCStringPtr(dateStr,
> CFStringGetSystemEncoding()),19); // yyyy-mm-dd hh:mm:ss'\0'

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.

  • Follow-Ups:
    • Re: CoreFoundation and CFDate functions - question on memory de-allocation
      • From: mmalcolm crawford <email@hidden>
    • Re: CoreFoundation and CFDate functions - question on memory de-allocation
      • From: Kent Behrends <email@hidden>
References: 
 >CoreFoundation and CFDate functions - question on memory de-allocation (From: Kent Behrends <email@hidden>)

  • Prev by Date: CoreFoundation and CFDate functions - question on memory de-allocation
  • Next by Date: Sensor readings
  • Previous by thread: CoreFoundation and CFDate functions - question on memory de-allocation
  • Next by thread: Re: CoreFoundation and CFDate functions - question on memory de-allocation
  • Index(es):
    • Date
    • Thread