Git Product home page Git Product logo

Comments (20)

daemelchi avatar daemelchi commented on June 1, 2024 3

daemelchi@1d8f002

from swiftgif.

tommylo avatar tommylo commented on June 1, 2024 1

Even the view controller is deinit, the UIImage with gif is not released.

from swiftgif.

miktav avatar miktav commented on June 1, 2024 1

The fix proposed by @daemelchi seems to have resolved the leak. I also had to set the UIImage property to nil in viewDidDisappear.

from swiftgif.

bahlo avatar bahlo commented on June 1, 2024

Hey @ravifullestop, thanks for making an issue!

I didn't test it with gifs this big, but I will look into it as soon as I have more time. ๐Ÿ‘

from swiftgif.

rhenz avatar rhenz commented on June 1, 2024

+1

from swiftgif.

nleachCHS avatar nleachCHS commented on June 1, 2024

+1

from swiftgif.

abdulaziz-jm avatar abdulaziz-jm commented on June 1, 2024

+1

from swiftgif.

samheather avatar samheather commented on June 1, 2024

+1 - just loaded a 2.8mb Gif, 2000x2000 and memory usage went to 1GB before crashing out

from swiftgif.

bahlo avatar bahlo commented on June 1, 2024

Sorry I'm only replying so late. ๐Ÿ˜ž

Since SwiftGif puts all frames in a UIAnimatedImage and even duplicates them to match various framerates, the memory leak is easily explained. It's just a lot of memory used.

We could render only a sequence of images at once (like lazy-load, plus drop earlier frames). This would add complexity to the library but help with this issue.
Another way is to throw an error if the gif is too big, but I don't really like that solution.

What do you guys think?

from swiftgif.

samheather avatar samheather commented on June 1, 2024

I'm still a little confused at how all the space is been used. Let's take an example:

800x800px GIF with 138 frames and transparency. The GIF is 2.8mb.

With SwiftGif, the memory increase from loading this Gif is ~290mb. So each of those 138 frames is taking 290/138 = 2.1Mb somehow.

Whereas if I export a (any) frame of my Gif from Photoshop it's about 87kb (24x less).

Why does extracting each frame from a gif take so much more memory that just rendering each frame individually as a PNG and loading all of those? If we answer that it might help work out a solution?

from swiftgif.

bahlo avatar bahlo commented on June 1, 2024

From the README.md:

How does it work?

Easy, it does the following:

  1. Find out the duration of every frame
  2. Find the greatest common divisor
  3. Add frames accordingly to the greatest common divisor to an array
  4. Create an animated UIImage with the frames

So if the greatest common divisor is, say, one second, images that are displayed ten seconds would get added ten times. This may be the problem.

from swiftgif.

samheather avatar samheather commented on June 1, 2024

Yeah it sounds like it. I wonder if there's an optimisation by allowing flexibility in the greatest common divisor, i.e. if we've got frames of 9, 10, 20, 30, 40, we'd have to use GCD of 1, whereas the effect of using 10 would probably be minimal. It could be a toggle-able optimisation - a 10% deviation in the GCD value?

from swiftgif.

petaire92 avatar petaire92 commented on June 1, 2024

+1

from swiftgif.

petaire92 avatar petaire92 commented on June 1, 2024

Any news on this ?

from swiftgif.

Mozahler avatar Mozahler commented on June 1, 2024

You are using:
func CGImageSourceCreateWithData(_ data: CFData, _ options: CFDictionary?) -> CGImageSource?
Which Creates an image source that reads from a Core Foundation data object.
returns: An image source. You are responsible for releasing this object using CFRelease.

I don't see any calls to CFRelease in your code. This means that the memory used during each call is retained and never deallocated.

from swiftgif.

olilavoie avatar olilavoie commented on June 1, 2024

The fix proposed by @daemelchi should be pull requested. The defer fixed the leak I had in my app.

from swiftgif.

alessandro-martin avatar alessandro-martin commented on June 1, 2024

@bahlo Could you please merge @daemelchi's fix and issue a new release?
Also, @daemelchi could actually make a PR :)

from swiftgif.

bahlo avatar bahlo commented on June 1, 2024

Hey guys, sorry for the problems. @daemelchi can you please create a PR so we can resolve this?

from swiftgif.

SolDiez90 avatar SolDiez90 commented on June 1, 2024

Switching view controllers doesn't release the gif from memory which causes massive memory leaks especially for quite big gifs. I solved this by loading the UIImage in an appdelegate class but this is just a workaround.

from swiftgif.

JayeshPoriya avatar JayeshPoriya commented on June 1, 2024
  1. When I switching view controller, Gif doesn't release memory. How can I deal with this issue?
    How can I manage OR solve this issue?
  2. When I try to load some other GIF with same viewcontroller on same imageview (On different button action), It's going to very horrible memory leak. It's going to 650MB.
    Please Help.

from swiftgif.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.