Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Memory leak calling perl from ObjC

Help
2007-08-03
2013-04-25
  • Colin Henein
    Colin Henein
    2007-08-03

    Greetings. I'm trying to use CamelBones to access the Perl module Image::ExifTool from Objective-C.

    When I execute multiple calls to this module from a test perl script nothing grows, but when I make multiple calls from CamelBones my process bulks up very fast.

    I initialize one CBPerl object like so:
            cbp = [[CBPerl alloc] init];
            [cbp useModule: @"Image::ExifTool"];
            [cbp eval: @"$exifTool = new Image::ExifTool"];

    then I have the following method that does a run for one file:

    - (NSDictionary*)exifDataForPath: (NSString*)path
    {
        [cbp setValue:path forKey:@"path"];
        [cbp eval: @"%info = %{$exifTool->ImageInfo($path)}"];
       
        // must remove array and scalar references as they cause exceptions in the CBDictionary.
        [cbp eval: @" foreach (keys %info) { my $val = $info{$_}; if (ref $val eq 'ARRAY') { $info{$_} = join(', ', @$val); } elsif (ref $val eq 'SCALAR') { $info{$_} = '(Binary data)'; } }"];
       
        CBPerlHash *perlHash = [CBPerlHash dictionaryNamed:@"info"];
        NSDictionary *ret = [NSDictionary dictionaryWithDictionary: perlHash]; // copy into ObjC
        [cbp eval: @"undef %info; undef $path; "];
        NSLog(@"Metadata at %@:\n%@", path, ret);
       
        return ret;
    }

    I call that method in a loop which allocates and clears an autorelease pool around each call.

    I can't find any way to avoid this memory leak. I'm trying to undef the variables when I'm done with them, but this does not seem to be getting perl to release the memory.

    I've run my process in ObjectAlloc, and I am not leaking dictionaries or CBPerlHash objects or anything like that. Instead, I see continuously increasing allocation attributed to libperl.

    Is it possible that CamelBones is keeping references to the hashes that I'm pulling through, even though the CBPerlHash objects are getting released?

    Please let me know if there's anything else you'd like me to try.

     
    • Colin Henein
      Colin Henein
      2007-08-09

      Sadly no response after a week.

      Is anyone here aware of a better forum or list that may be able to answer this question?