On Aug 11, 2008, at 1:12 PM, Sean DeNigris wrote:

Hi, how do I handle memory management for todoUid below? Do I have to retain or autorelease it?

I'm using Scripting Bridge to communicate with iCal. Also, this is a sub-routine and todoUid will only be used in the method that calls it.

- (NSString*) saveToiCalTodo: (NSString*) theSummary : (id) theDescription
{
        // Create new iCal todo
iCalTodo* newTodo = [[[iCal classForScriptingClass:@"todo"] alloc] init];
        
        // Add the todo to my iCal calendar
        [[myCalendar todos] addObject:newTodo];
        
        // Set its summary
        [newTodo setSummary:theSummary];
        
        // Store description
        [newTodo setObjectDescription: theDescription];
        
        // Get uid to return
        NSString* todoUid = [newTodo uid];
        
        // Clean up
        [newTodo release];
        newTodo = nil;
        
        return todoUid;
}

Thanks in advance!

You don't need to retain it here. Whatever method called this one should decide if it wants to retain it based on it's use of the uid. For example, the calling code may add the uid to an NSArray which handles keeping references to it's objects and thus you wouldn't retain it yourself. But if the calling code just stored it in an ivar then you may need to retain it based on how it's accessors are set up. Only the calling code would know which it needs.

You may want to read up on memory management:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html


A few points on style, it would be better to use a keyword for the theDescription parameter. It makes it easier to read and debug in the calling code. Also since you are returning a value I would add that to the method name.

A suggestion for an alternate method name... uidForSavingiCalTodoSummary: withDescription:

This allows someone reading/scanning the calling code to know what is being returned (uid), what is being done (saving), and what information is needed (a summary and a description).


--Nathan



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to