1 pixel image
1 pixel image

Code blog.

Here you will be able to download free source code, read about some of our coding experiences and learn some handy hints. The archives normally contain source in a mixture of C, Objective-C and C++, XML datafiles, required graphics and sounds and occasionally a Doxygen config file.

We use (and recommend) OpenGL and TinyXML, a great light XML parser.


1 pixel image
1 pixel image
most recent

August 2005

email jeroen
 1  2  3  4  5  6  7  8 9 10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31
1 pixel image
1 pixel image

Memory leak in previous post! Aaaarrgghhh!

August 2005

What have I done?

The entry Calling Applescript from Objective-C and Cocoa." from the 23 of July contains a memory leak published code.

Since I am very new to Cocoa and Objective-C I love to hear about corrections to my code, it's a very fast way of learning! This memory leak was reported by Guy, via the cocoa-dev lists at Apple:


Hey Jeroen,

Thanks for the code pointer, I'm going to nick that because it's
handy to have around. Less handy are the two memory leaks though. :)
scriptError and appleScript both leak - they're sent allocs but have
no matching release or autorelease. Also, even when you add a release
for the scriptError it'll leak anyway. :) executeAndReturnError: will
overwrite the pointer to the dictionary with the dictionary it creates
internally. It's not a very common idiom in Cocoa ( although there are
a few places that do use it ) but it's something to watch out for.

Here's the adjusted code below. Thanks for putting it up - the
image color automater thing is a very cool idea by the way. Try adding
face recognition and it'd be super-duper cool. :)

Take care,

Guy

A corrected version by Guy follows:

/*----------------------------------------------------------------------------*/
/**
* Add metadata comment to the file's current comment.
*
* \param (NSString*) file File path.
* \param toComment:(NSString*) comment The comment to add to the file's comment.
*/

-(void)setCommentForFile:(NSString*)file
toComment:(NSString*)comment
{
NSDictionary *scriptError = nil;


/* Create the Applescript to run with the filename and comment string... */
NSString *scriptSource = [NSString stringWithFormat:
@"on run\r tell application \"Finder\"\r set theFile to
(\"%@\") as alias\r set newComment to (comment of theFile) &
\"%@\"\r set comment of theFile to newComment\r end tell\r end run\r"
,
[self carbonPathFromPath:file], comment];

NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:scriptSource];

/* Run the script! */
if(![appleScript executeAndReturnError:&scriptError])
NSLog([scriptError description]);

[appleScript release];
}

I did do a bit of "research" recently into Cocoa memory usage and leak detection...
About the face recognition.... uh, no, not anytime soon! ;)


  

Archive

  May 2007
  April 2007
  ...
  2006? Oh, we missed it.
  ...
  October 2005
  September 2005
  August 2005
  July 2005
  June 2005
  May 2005
  April 2005
  March 2005
  February 2005
  January 2005
  December 2004
  November 2004
  October 2004
  September 2004
  August 2004