XamlAnimatedGif / WpfAnimatedGif

A simple library to display animated GIF images in WPF, usable in XAML or in code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eats ram

alexeygritsenko opened this issue · comments

Hi, I noticed that my application is very unstable when using your library. It turned out to consume a lot of memory, an inadequate amount. For example, to show an animation of 132 kb, ~ 600 mb of memory takes up. If I run the window several times, then the memory can grow up to 2GB and then the application crashes.

gif, screens, test app: https://yadi.sk/d/vuBMmDrkKH-FXQ

Hi @alexeygritsenko,

I'm aware that the library is a memory hog; it's been reported many times before. The issue is inherent to the way WpfAnimatedGif works: it prepares all frames in memory and then run an animation between them. It's one of the reasons why I made another library, which I suggest you use instead (it has performance issues for some large GIFs, but seems to work fine for your GIF)

I realize that 600MB for a 132KB file seems a bit extreme, but look at it this way: your GIF has many frames, and it's a fairly large image (787x581). There are many blank areas, which means it can be compressed efficiently, and in addition, the GIF format takes advantage of parts that don't change between frames, and only encodes the changes. So, the file is small because it was compressed efficiently, but it's actually a pretty big animation. As I said above, WpfAnimatedGif prepares all the frames in advance, in memory, uncompressed. So, yes, it takes a lot of space, there's no way around it, short of completely changing the way the library works, and I don't intend to do that (I did it in XamlAnimatedGif, but there's a performance trade-off). In fact, you probably shouldn't use a GIF for something like this; it should be a video. The GIF format was never intended to replace video.

OK. Replaced WpfAnimatedGif to XamlAnimatedGif gave a faster animation loading speed and also reduced memory consumption to 35mb. At the same time, the initial load on the CPU decreased from 25% to 5%.

Nice!
Yes, the animation starts faster with XamlAnimatedGif because it doesn't prepare all frames in advance.