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: RunStandardAlert leaking memory all over the place?



On Jun 11, 2006, at 2:06 PM, Rosyna wrote:

Other than the fact you're not checking for NULL when using CFRelease(). I've learned to not trust any CF API to never return NULL except CFSTR() (and I'm even hesitant on that).

But is this happening in another thread? It looks like this is a cocoa application and if you're doing this in another thread, you need to wrap the insides of the function with an NSAutoreleasePool, much like almost anything at Jack in the Box.

UI elements shouldn't really be invoked in anything but the main thread. At least, that's my understanding.



Ack, at 6/11/06, Richard Bannister said:

I've got some code calling CreateStandardAlert/RunStandardAlert that is leaking a whole truck load of memory.

Have you tried printing out the retain counts on the strings you're loading/using...


void shareware_annoy(void)
{
	AlertStdCFStringAlertParamRec		paramRec;
	OSStatus							err;
	DialogRef							alert;
	DialogItemIndex						itemHit;
	CFStringRef 	def, can, oth, tit, det;

// Load strings
def = CFCopyLocalizedStringFromTable(CFSTR("Yes Please"), CFSTR ("Shareware"), "SW_DEFAULT");
can = CFCopyLocalizedStringFromTable(CFSTR("Maybe Later"), CFSTR ("Shareware"), "SW_CANCEL");
oth = CFCopyLocalizedStringFromTable(CFSTR("Reinstall"), CFSTR ("Shareware"), "SW_OTHER");
tit = CFCopyLocalizedStringFromTable(CFSTR("Brain Box is a shareware product. Would you like to register now?"), CFSTR ("Shareware"), "SW_TITLE");
det = CFCopyLocalizedStringFromTable(CFSTR("This message appears on program launch. It can be removed permanently by paying the shareware fee instantly online via credit card."), CFSTR ("Shareware"), "SW_DETAIL");

-- here --

// Get defaults
GetStandardAlertDefaultParams(&paramRec, kStdCFStringAlertVersionOne);
paramRec.defaultText = def;
paramRec.cancelText = can;
paramRec.otherText = oth;
err = CreateStandardAlert(kAlertCautionAlert, tit, det, &paramRec, &alert);

-- here --

	// Release all the strings now, since they'll be retained above.
	CFRelease(def);
	CFRelease(can);
	CFRelease(oth);
	CFRelease(tit);
	CFRelease(det);

-- here --

	// Run the alert
	if (err == noErr)
	{
		err = RunStandardAlert(alert, NULL, &itemHit);

-- and here --

	}
}

Plus, as Rosyna mentioned, it would be a good idea to test that CFCopyLocalizedStringFromTable did, in fact, return each of the strings you wanted, and then release only those that came back as non- null. If you're calling CFRelease on a null string, who knows what that's doing to the heap.


An interesting test would also be to release all the strings after calling RunStandardAlert to see if any of the other allocations get cleaned up.

steve

_______________________________________________
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
References: 
 >RunStandardAlert leaking memory all over the place? (From: Richard Bannister <email@hidden>)
 >Re: RunStandardAlert leaking memory all over the place? (From: Rosyna <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.