Mailing Lists: Apple Mailing Lists

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

Releasing (Xcode 1.5 & 10.3.9)?



I'm wondering why a released CFDataRef returns a valid value using CFDataGetBytePtr?
Does CFRelease actually deallocate/free memory which is allocated and copied from source memory?
If not, where and how do I free the memory that the dataRef has been holding?


int main ()
{
     const char*  kMyName = "Norio Ota";
	size_t len = strlen (kMyName);
	char *		newString, *dStr;
	CFDataRef	data;
	
	newString = (char*) malloc (len + 1);
	memcpy (newString, kMyName, len);
	newString[len] = '\0';
	
	data = CFDataCreate (kCFAllocatorDefault, newString, len +1);
	CFShow (data);
	fprintf (stderr, "newString is %s\n", newString);
	free (newString);

	fprintf (stderr, "freed newString is %s\n", newString);
	
	CFShow (data);
	CFRelease (data);

	dStr = CFDataGetBytePtr (data);
	fprintf (stderr, "after releasing, stored newString is %s\n", dStr);

 return 0;
}

The log is something like below.


<CFData 0x11011d0 [0xa01c00e0]>{length = 10, capacity = 10, bytes = 0x4e6f72696f204f746100}
newString is Norio Ota
freed newString is
<CFData 0x11011d0 [0xa01c00e0]>{length = 10, capacity = 10, bytes = 0x4e6f72696f204f746100}
after releasing, stored newString is Norio Ota



As you can see, despite the data was released before being called CFDataGetBytePtr, it returns a value which seems to be valid.


Thanks,
Norio


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to 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.