[Bins] bins memory leak SOLVED

Corporate Gadfly corporate_gadfly at hotmail.com
Sat Feb 10 22:29:54 GMT 2007


Hi bins users,

As most of you are aware, bins 1.27+ (including latest 1.29) has a memory 
leak. Large albums with 1000s of pictures were consuming around 500M on my 
computer. I believe I have fixed it and now the memory consumption is around 
25M. I think it was caused by Revision 1.163:

http://kashmir.sautret.org/cgi-bin/viewcvs.cgi/bins/bins?r1=1.162&r2=1.163

To reverse the affects of this revision, I have tried to not use sub 
getFields and sub getIntlSubs as almost all the values need only be 
initialized once at the beginning. In addition, I made some dateString 
related assignments immediately after reading the config file.

I would like to invite people to see if this "memory leak" bug is fixed. In 
addition, you might find that bins runs a little faster as well.

Find attached, the patch.

On another note, Jerome hasn't responded on the mailing list for quite some 
time. His last commit to the CVS repo was more than a year ago. I hope this 
doesn't mean that the project has been abandoned? How will we get this 
change into the next release (if indeed this is the correct fix)?

Regards,
--
Haroon

P.S. Here's the patch inline:

===================================================================
RCS file: ./RCS/bins-1.29,v
retrieving revision 1.2
diff -u -r1.2 ./bins-1.29
--- ./bins-1.29 2005/11/13 01:46:57     1.2
+++ ./bins-1.29 2007/02/10 20:58:54
@@ -449,13 +449,13 @@
$defaultConfig{fileActiveSizeNames} = \@fileActiveSizeNames;

# Fields to display (in the list order) under the picture. These
-# fields are defined in the getFields function below.
+# fields are defined in the %fields hash below.
my @mainFields = ("description", "people", "location", "date",
                                   "event", "comment");


# Fields to display (in the list order) in the details page. These
-# fields are in the getFields function below.
+# fields are in the %fields hash below.
my @secondaryFields = (
                        # DigiCam
                        _("BINS-SECTION DigiCam Info"),
@@ -519,7 +519,6 @@
                        "BINS-SECTION end", # close the last section
                        );

-sub getFields {
     # The key is the string used as the name in the picture
     #   description file.
     # Name corresponds to the string displayed under the picture.
@@ -527,9 +526,8 @@
     #   found in some JPEG images.
     # The value of the EXIF structure is only used if no value
     #   is present in the picture description file.
-    # Transform is a Perl operator used to convert an exif value
-    #   to the desired format to display.  It is evaluated as
-    #   normal Perl code and the result has to be in $_.
+    # Note: See also postProcessHashArrays() for dateString related
+    # items
     my %fields =
           (
          "title" =>
@@ -547,12 +545,6 @@
          "date" =>
          { Name => _("Date"),
            EXIF => "DateTimeOriginal",
-           Transform => '$_ = local2html(strftime 
$configHash->{dateString}, gmtime str2time "$_") if str2time "$_"',
-           # Alternatively, you could use regex substitution:
-           # English version is yyyy:mm:dd hh:mm:ss to yyyy/mm/dd hh:mm:ss 
:
-           # Transform => 's%^(\\d+):(\\d+):(\\d+) (.*)$%\$1/\$2/\$3 \$4%',
-           # French version is yyyy:mm:dd hh:mm:ss to dd/mm/yyyy hh:mm:ss :
-           # Transform => 's%^(\d+):(\d+):(\d+) (.*)$%$3/$2/$1 $4%',
                  },

              "event" =>
@@ -822,8 +814,6 @@
            Tip => _("Indicates the image sensor type on the camera or input 
device."),
        },
          );
-    return \%fields;
-}

my @priorityExifTags = ();  # the field in this list are taken from
# the desc file, even if they are present
@@ -847,10 +837,10 @@
                 });
$defaultConfig{colorsSubs} = \%colorsSubs;

-sub getIntlSubs{
-    my $configHash = shift;
-    # Strings to translate in the HTML template pages (if I18N is used)
-    my %intlSubs = (  STRING_THUMBNAILS   => _("thumbnails"),
+# Strings to translate in the HTML template pages (if I18N is used)
+# Note: See also postProcessHashArrays() for dateString related
+# items
+my %intlSubs = (  STRING_THUMBNAILS   => _("thumbnails"),
                       STRING_IMAGELIST    => _("Image List"),
                       STRING_HOME => _("Home"),
                       STRING_ALBUM => _("Album"),
@@ -882,13 +872,11 @@
                       BINS_VERSION             => "1.1.29",
                       ENCODING                 => 
$defaultConfig{htmlEncoding},
                       GENERATED_DATE       => _("on ").
-                      local2html(strftime($configHash->{dateString},
+                      local2html(strftime($defaultConfig{dateString},
                                           localtime)),
                       BINS_ID =>
                       '<!--$Id: bins-1.29,v 1.2 2005/11/13 01:46:57 haroon 
Exp haroon $-->',
                       );
-    return \%intlSubs;
-}

# @knownImageExtentions defines file extensions that BINS can handle as
# input image. BINS _should_ handle all input format of ImageMagick
@@ -925,6 +913,7 @@
sub beVerboseN;
sub min;
sub readConfigFile;
+sub postProcessHashArrays;
sub fileSize;
sub generateAlbumPages;
sub filenameToPreviewName;
@@ -942,8 +931,6 @@
sub trimWhiteSpace;
sub stringToBool;
sub ignoreSet;
-sub getFields;
-sub getIntlSubs;

sub generateThumbnailPages;
sub generateThumbEntry;
@@ -1005,6 +992,27 @@
     return \%option;
}

+# process hash arrays after reading config file
+# a non-default value of dateString might have been read from the
+# configuration file, so the proper values must be inserted into the
+# %fields and %intlSubs hash arrays
+sub postProcessHashArrays {
+    my $configHash = shift;
+
+    # Transform is a Perl operator used to convert an exif value
+    #   to the desired format to display.  It is evaluated as
+    #   normal Perl code and the result has to be in $_.
+    $fields{date}{Transform} =
+        '$_ = local2html(strftime $configHash->{dateString}, gmtime 
str2time "$_")';
+           # Alternatively, you could use regex substitution:
+           # English version is yyyy:mm:dd hh:mm:ss to yyyy/mm/dd hh:mm:ss 
:
+           # Transform => 's%^(\\d+):(\\d+):(\\d+) (.*)$%\$1/\$2/\$3 \$4%',
+           # French version is yyyy:mm:dd hh:mm:ss to dd/mm/yyyy hh:mm:ss :
+           # Transform => 's%^(\d+):(\d+):(\d+) (.*)$%$3/$2/$1 $4%',
+    $intlSubs{GENERATED_DATE} = _("on ").
+            local2html(strftime($configHash->{dateString}, localtime)),
+}
+
# process command line arguments after reading config file
sub postProcessArgs {
     my $option = shift;
@@ -1257,6 +1265,9 @@
     # read configurations files
     my $defaultConfig = readConfigFile(\%defaultConfig);

+    # post process %fields and %intlSubs hash arrays
+    postProcessHashArrays($defaultConfig);
+
     # post process command line args after reading config files
     postProcessArgs($options, $defaultConfig);

@@ -2934,7 +2945,7 @@
             $sectionTitle = $tagName;
             $sectionTitle =~ s/^BINS-SECTION //;
         }else{
-            $tagValue = getFields($configHash)->{$tagName};
+            $tagValue = $fields{$tagName};
             if ($imageInfo->{$tagName}) {
                 my %row = (FIELD_NAME => $tagValue->{'Name'},
                            FIELD_VALUE => 
local2html($imageInfo->{$tagName})
@@ -2989,7 +3000,7 @@
     $subs_hash{CUSTOM_CSS} = $configHash->{customStyleSheet};

     my @array;
-    push @array, {NAV_NAME => 
getIntlSubs($configHash)->{STRING_BACKTOTHEIMAGE},
+    push @array, {NAV_NAME => $intlSubs{STRING_BACKTOTHEIMAGE},
                   NAV_LINK => "javascript:history.back();",
                   NAV_ICON => "back.png",
                   NAV_ID => "back"};
@@ -3649,7 +3660,7 @@
         if (${%$hashref}{$tagName}) {
             my $value=${%$hashref}{$tagName};
             $value =~ s/'/&#39;/g  ; # in case it's used in javascript code
-            push @descTable, {DESC_FIELD_NAME => 
getFields($configHash)->{$tagName}->{'Name'},
+            push @descTable, {DESC_FIELD_NAME => 
$fields{$tagName}->{'Name'},
                               DESC_FIELD_VALUE => $value,
                           };
         }
@@ -3794,7 +3805,7 @@
     %{$templateParameters} =
         (%{$templateParameters},
          %{$configHash->{colorsSubs}{$configHash->{colorStyle}}},
-         %{getIntlSubs($configHash)},
+         %intlSubs,
          );

     # open the html template
@@ -3922,7 +3933,7 @@
                 && $element->{Name} eq "field") {
                 $fieldName = $element->{Attributes}{'name'};
                 $fieldValue = "";
-                if (grep (/^$fieldName$/, keys(%{getFields($configHash)}))) 
{
+                if (grep (/^$fieldName$/, keys(%fields))) {
                     beVerbose("    Reading field '$fieldName':", 3);
                     foreach my $characters (@{$element->{Contents}}) {
                         #if (UNIVERSAL::isa($characters, 
'XML::Grove::Characters')) {
@@ -4348,13 +4359,13 @@
     }

     # add value to desc Hash if field is void
-    foreach my $field (keys(%{getFields($configHash)})) {
-        my $fieldExif = getFields($configHash)->{$field}->{'EXIF'};
+    foreach my $field (keys(%fields)) {
+        my $fieldExif = $fields{$field}->{'EXIF'};
         if ((! $descHash->{$field}) && $fieldExif && 
$exifHash->{$fieldExif}) {
             beVerboseN("  Using '$field' from EXIF data: ".
                        $exifHash->{$fieldExif}, 3);

-            my $func = getFields($configHash)->{$field}->{'Transform'};
+            my $func = $fields{$field}->{'Transform'};
             if ($func) {
                 $_ = $exifHash->{$fieldExif};
                 beVerbose("  Evaluating '$func' from '$_'", 4);

_________________________________________________________________
Check out all that glitters with the MSN Entertainment Guide to the Academy 
Awards®   http://movies.msn.com/movies/oscars2007/?icid=ncoscartagline2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bins-1.29-memory-leak.diff
Type: text/x-patch
Size: 8528 bytes
Desc: not available
Url : https://www.email-lists.org/pipermail/bins/attachments/20070210/c9d3e539/bins-1.29-memory-leak.bin


More information about the Bins mailing list