avoid unneeded memory allocation on loader cancelation, it can grow a lot :/
authorGuillaume Cottenceau <gcottenc@gmail.com>
Mon, 21 Dec 2009 15:50:25 +0000 (16:50 +0100)
committerGuillaume Cottenceau <gcottenc@gmail.com>
Mon, 21 Dec 2009 15:50:25 +0000 (16:50 +0100)
bin/booh-classifier

index 5b4c69d..0dbf1d5 100644 (file)
@@ -410,6 +410,19 @@ class Entry
         end
     end
 
+    def cancel_loader
+        if ! @loader.nil?
+            #- avoid unneeded memory allocation
+            @loader.signal_handler_disconnect(@area_prepared_cb)
+            begin
+                @loader.close
+            rescue
+                #- ignore loader errors, at that point they are fairly normal, we're canceling a partial load
+            end
+            @loader = nil
+        end
+    end
+
     private
     def load_into_pixbuf_full
         if @pixbuf_full.nil?
@@ -463,7 +476,7 @@ class Entry
                 @loader.signal_connect('size-prepared') { |l, w, h|
                     @loader.set_size(*specify_size.call(w, h))
                 }
-                @loader.signal_connect('area-prepared') { @loaded_pixbuf = @loader.pixbuf }
+                @area_prepared_cb = @loader.signal_connect('area-prepared') { @loaded_pixbuf = @loader.pixbuf }
                 @loader_offset = 0
             end
             msg 3, "calling load_not_freezing_ui on #{image_path}, offset #{@loader_offset}"
@@ -1905,13 +1918,7 @@ end
 
 def cleanup_loaders
     $allentries.each { |e| 
-        if ! e.loader.nil?
-            begin
-                e.loader.close
-            rescue
-                #- ignore loader errors, at that point they are fairly normal
-            end
-        end
+        e.cancel_loader
     }
 end