Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp Script Memory Problem Question
#1
Bug 
Hello,

I am producing a batch of images with Python/Gimp Scriptfu

But it seems on every round of the loop I am accumulating unnecessary Memory. Eventually this leads to a Memory Error. 

It looks like pdb.gimp_image_delete(image) is not working. It should return True on success but that isn't the case.

Anyone experienced similar issues or knows whats wrong? I am using Gimp 2.1 on MacOS

Or is there another way to simply clear the memory cache of GIMP after each round of the loop or whenever needed?

Thanks a lot!w_

Timage)
Reply
#2
Can you show the actual code that loads the image, and the code that deletes it?

You can also check if according to Gimp the length of the image list (obtained by gimp.image_list() isn't increasing indefinitely).

"It should return True on success but that isn't the case." I don't see this documented in the procedure browser... For me it doesn't return anything.



Tried this:
Code:
for i in range(10):
    image=gimp.Image(30000,30000,RGB)
    layer=gimp.Layer(image,"Filler",10000,10000,RGB_IMAGE,100,NORMAL_MODE)
    image.add_layer(layer,0)
    pdb.gimp_drawable_fill(layer,FILL_PATTERN)

for image in gimp.image_list():
    print image.layers

# A bit later

for image in gimp.image_list():
    gimp.delete(image)
With my system monitor running, I definitely see a memory increase, and a final sharp drop:

   

While doing this, I found that the Image list dockable dialog displays the image thumbnails, even if they have no associated Display, so perhaps just by opening this dialog you can check if your images are adequately removed (I can see the images appear in the display one by one, and then all disappear at the end).
Reply
#3
Thanks a lot for that quick reply! Didn't expect that.
So I tried that.
gimp.image_list():
Seems its working fine because it returns always
Image List: (1, (1,)) and not increasing. Not sure what 1, 1 is for if this array is empty.

I am now testing for another Bug in my Python Code which is quite big. Maybe a different Array not related to GIMP is was causing this error inside of the loop and causing this huge memory increase from 3GB to 60GB.

Thanks a lot this function really helped to test for it.
I will let you know once I am able to fix it.
Reply
#4
(12-19-2021, 02:38 PM)KoalaBear2022 Wrote: Thanks a lot for that quick reply! Didn't expect that.
So I tried that.
gimp.image_list():
Seems its working fine because it returns always
Image List: (1, (1,)) and not increasing. Not sure what 1, 1 is for if this array is empty.

You ask in Python and you get an answer in Scheme? Looks like a list of one image where the first image ID is 1.

By the way the Python script runs in its own process you can tell in your System monitor is the RAM is used by  your Python script or by Gimp itself.
Reply
#5
Did this with a 1690x2225px images and 10K iterations, and I can just see a small 300MB increase since I started (and since I have other apps running, it may not be due to Gimp)
Reply
#6
I am getting still the same result. I even disabled/enabled the Undo with image.disable_undo()/ image.enable_undo() which could possibly reduce memory consumption.

Are you modifying/processing your image at each iteration?

I am guessing GIMP is saving some Data once you change/modify something on your image.
ChameleonScales mentioned the use of pdb.gimp_item_delete because GIMP apparently does save this information on each iteration. But I am not sure on what "items" I would need to delete. I am not even sure what exactly an item is. Total Noob but also almost no info on the net.

***
I just tested again and apparently gimp.image_list() returns increasing numbers just before I perform image.delete at each iteration;

So this would be for iteration 37 before image_delete: Image List: (2, (38, 1))
and after using pdb.gimp_image_delete(new_image): Image List: (1, (1,))

This would be for iteration 38 before image_delete: Image List: (2, (37, 1))
and after using pdb.gimp_image_delete(new_image): Image List: (1, (1,))

and so on:
And iteration 100 would be Image List: (2, (99, 1))
and again after pdb.gimp_image_delete(new_image) Image List: (1, (1,))

and so on.. so that means Image List is actually increasing somehow even though it would show (1, (1,)) immediately after using pdb.gimp_image_delete(new_image)
Reply
#7
(12-20-2021, 08:11 PM)KoalaBear2022 Wrote: I am getting still the same result. I even disabled/enabled the Undo with image.disable_undo()/ image.enable_undo() which could possibly reduce memory consumption.

Are you modifying/processing your image at each iteration?

I am guessing GIMP is saving some Data once you change/modify something on your image.
ChameleonScales mentioned the use of pdb.gimp_item_delete because GIMP apparently does save this information on each iteration. But I am not sure on what "items" I would need to delete. I am not even sure what exactly an item is. Total Noob but also almost no info on the net.

***
I just tested again and apparently gimp.image_list() returns increasing numbers just before I perform image.delete at each iteration;

So this would be for iteration 37  before image_delete: Image List: (2, (38, 1))
and after using pdb.gimp_image_delete(new_image): Image List: (1, (1,))

This would be for iteration 38  before image_delete: Image List: (2, (37, 1))
and after using pdb.gimp_image_delete(new_image): Image List: (1, (1,))

and so on:
And iteration 100 would be Image List: (2, (99, 1))
and again after pdb.gimp_image_delete(new_image) Image List: (1, (1,))

and so on.. so that means Image List is actually increasing somehow even though it would show (1, (1,)) immediately after using pdb.gimp_image_delete(new_image)

You have all of my code. Do you see a memory creep when you use it?

These increasing numbers are expected, The first image has ID 1, the next ID 2, the next ID 3, etc... So you see a list of two images with your initial image (ID 1 and the one for the current iteration (ID 37).

Also, is the moroy creep in the Gimp process or in the Pythin one?
Reply
#8
Thanks for your replies and infos. This is very useful.

So I tested your code as well. Your code has a big memory increase too from 1 to 10 GB on the GIMP process and then reduces when the loop finishes. But this iterates only 10 times. I guess on a larger iteration it would create similar problems.

The memory creep is definitely on the GIMP Process. 

Attached you can see a Screenshot on the Error when GIMP crashes.




Attached Files Thumbnail(s)
   
Reply
#9
What is your Gimp version? I tested on 2.10.22 (not on 2.10.28 yet).
Reply
#10
(12-21-2021, 05:03 PM)Ofnuts Wrote: What is your Gimp version? I tested on 2.10.22 (not on 2.10.28 yet).

 It is: GIMP 2.10.24
Reply


Forum Jump: