Apparent memory leak

Discussion about writing code for Inkscape.
lemmywinks
Posts: 4
Joined: Tue Oct 01, 2013 10:10 am

Apparent memory leak

Postby lemmywinks » Tue Oct 01, 2013 10:51 am

Im using windows 8 with as far as i know using the latest inkscape version. So say i add an item to my canvas or whatever you call it, the item is 5mb, and i then go and delete that item. The item is gone but my file size is still 5mb. Ive pasting in images, taking pictures and then deleting and modifying what i have on the canvas and taking another picture etc. So obviously given that memory is apparently not being freed upon deletion the file size grows and grows, it starts to become fairly unstable at around 50mb (crashes) and once it gets to around 63mb i basically cant do anything to it without it crashing.

So ya this seems like it would be a big problem, or atleast for anyone doing what im doing with larger files. Have to consistently make new files and copy paste what i have over to the new one to get rid of the non-freed memory to prevent crashes later on.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Apparent memory leak

Postby Lazur » Wed Oct 02, 2013 8:50 am

I'm guessing that is the price for having unlimited undo-s?
Does a simple save and quitting, then reopening help?
If not there is something unnecessary saved in the svg. Maybe there are unused defs that you can clear too.

lemmywinks
Posts: 4
Joined: Tue Oct 01, 2013 10:10 am

Re: Apparent memory leak

Postby lemmywinks » Wed Oct 02, 2013 3:42 pm

No saving, quitting and coming back in doesn't do anything. When i do this i can no longer undo but the memory is still being consumed.

User avatar
druban
Posts: 1917
Joined: Fri Nov 20, 2009 10:48 pm

Re: Apparent memory leak

Postby druban » Wed Oct 02, 2013 5:46 pm

If you are saying that your file size keeps growing even if you save it and quit Inkscape and then reopen it, that is very unusual behavior and I would like to see it happen. An SVG is completely readable, i.e. there is nothing in it that is hidden. So if you delete everything from your canvas that you can see and then save the file to disk and find that the supposedly empty file Is 50MB it should be easy to see where that is coming from. If that does not happen, then it must be some element in your file that is the problem.
Are you working with large raster images and embedding them?
Are you making many duplicates of objects using tiled clones for example? Are you using a lot of filters and blurs?
If (for example) you open a 5MB JPEG in Inkscape and do a filter operation on it. A highly compressed 5MB jpeg could easily decompress to a very large PNG, which is what Inkscape would use to work with the file because of the blur or filter (not always, though, I think sometimes the original might be embedded as is). I have found it a good practice to only feed PNG files into Inkscape, although that might be a habit acquired long ago before JPEG import :D . I can't remember.
This kind of file (embedded large raster) would inevitably bring Inkscape to a grinding halt for most medium powered computers... You could try switching to outline view if this is indeed the cause. Also you could try linking and not embedding imported images.
The undo buffer should be cleared when a save is completed so unlikely to be the cause.....
Your mind is what you think it is.

lemmywinks
Posts: 4
Joined: Tue Oct 01, 2013 10:10 am

Re: Apparent memory leak

Postby lemmywinks » Thu Oct 03, 2013 8:34 am

So if you delete everything from your canvas that you can see and then save the file to disk and find that the supposedly empty file Is 50MB it should be easy to see where that is coming from.

This is what is happening, how do i read this file, am i able to read it and delete the unfreed memory while keeping what i want, obviously id have to be able to distinguish between the two.

Are you making many duplicates of objects using tiled clones for example?

Im making duplicates of large objects that are covered with patterned textures, the images that function as textures i believe are linked not embedded.

Wish it didn't take a day for a post to be approved don't know how communication on such a forum is really feasible. I will probabbly have to redo one of these scenes because the file has become too large and unstable, if there is no way to fix it.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Apparent memory leak

Postby Lazur » Thu Oct 03, 2013 8:46 am

There is an option under the file menu to delete unused defs.
Vacuum defs, or clean defs?

If you cannot open such a big file, you can still open the svg in a notepad and edit things out of the defs section manually.

There is a bug that creates many unused defs I know of:
when you clone an object with a gradient and modify the parent's gradient's handle,each small modification gets saved too.
That was the main reason for cracking in my experience.

User avatar
druban
Posts: 1917
Joined: Fri Nov 20, 2009 10:48 pm

Re: Apparent memory leak

Postby druban » Thu Oct 03, 2013 6:39 pm

lemmywinks wrote:So if you delete everything from your canvas that you can see and then save the file to disk and find that the supposedly empty file Is 50MB it should be easy to see where that is coming from.
This is what is happening, how do i read this file, am i able to read it and delete the unfreed memory while keeping what i want, obviously id have to be able to distinguish between the two.

Let's just try one more thing because opening a 50mb file in a text editor is no laughing matter. Once you have everything deleted that you can see it's time to delete things that you can't see. First do a vacuum defs or a clean up document(depending on your version). Keep a sharp eye on the status bar at the bottom of the Inkscape window which will tell you how much cruft was removed. It's unlikely to be 50mb worth, but hey, we can hope. Save the file immediately after. Quit Inkscape and check the file size. Still huge? Darn.
Back to the drawing board (canvas in this case.)
With the blank canvas in front of you do a ctrl+alt+A (select all in all layers). Did that select anything? Check in the status bar again to see how many invisible little (or big) fish you have caught with your magic command. Delete them and see if that does it for your file size. Come back here and post a picture of the stuffed shark, or if it doesn't work tell us about the one that got away and there will be more ideas...

The whole point of all this is to see which the problem object is so you can go back to your original file and just delete that item. If it is an invisible item it does not have any impact on your file. if they are unused defs also no impact.
Your mind is what you think it is.

lemmywinks
Posts: 4
Joined: Tue Oct 01, 2013 10:10 am

Re: Apparent memory leak

Postby lemmywinks » Sat Oct 05, 2013 9:44 am

Vaccum defs worked, reduced from 55mb to 9mb, thanks everyone.


Return to “Programming”