Re: CoreFoundation and CFDate functions - question on memory de-allocation
Re: CoreFoundation and CFDate functions - question on memory de-allocation
- Subject: Re: CoreFoundation and CFDate functions - question on memory de-allocation
- From: Kent Behrends <email@hidden>
- Date: Thu, 8 Jan 2004 00:39:35 -0800
On Jan 7, 2004, at 11:22 PM, j o a r wrote:
Are you doing this with CF-functions for performance reasons?
No - Just using C not Obj-C :)
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.
Ya - some of the routines say the programmer is responsible of
releasing the allocated memory. I just haven't found an example showing
a CFDate being released...
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'
---
Kent Behrends
BEHR Consulting International
+1.909.393.5265 Office
+1.909.642.2747 Cell
+1.630.214.6898 FAX
http://www.bci.com
_______________________________________________
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.