Comments (20)
from swiftgif.
Even the view controller is deinit, the UIImage with gif is not released.
from swiftgif.
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.
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.
+1
from swiftgif.
+1
from swiftgif.
+1
from swiftgif.
+1 - just loaded a 2.8mb Gif, 2000x2000 and memory usage went to 1GB before crashing out
from swiftgif.
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.
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.
From the README.md
:
How does it work?
Easy, it does the following:
- Find out the duration of every frame
- Find the greatest common divisor
- Add frames accordingly to the greatest common divisor to an array
- 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.
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.
+1
from swiftgif.
Any news on this ?
from swiftgif.
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.
The fix proposed by @daemelchi should be pull requested. The defer fixed the leak I had in my app.
from swiftgif.
@bahlo Could you please merge @daemelchi's fix and issue a new release?
Also, @daemelchi could actually make a PR :)
from swiftgif.
Hey guys, sorry for the problems. @daemelchi can you please create a PR so we can resolve this?
from swiftgif.
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.
- 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? - 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)
- Animation stops when image is resized. HOT 1
- Animation Speed HOT 3
- Fail to Load GIF in new xcode 10 update with ios 12 HOT 4
- when i use loadGif error occur HOT 2
- Image not cache HOT 1
- Swift 5.0 support
- Refresh UITableViewCell gif speed auto increase
- After clear gif cannot set image on it
- only support iOS 10+ by carthage
- Crash on "func delayForImageAtIndex(_ index: Int, source: CGImageSource!) -> Double" HOT 3
- Memory leak inside setGIFFromURL
- iOS 13 support for traitCollection.userInterfaceStyle (Dark mode)
- Gif animations play at different speeds on iPad vs iPhone HOT 1
- Unknown class GIFImageView in Interface Builder file. HOT 1
- Takes lot of memory more than 700 MB just to play GIF in Imageview. HOT 1
- How to check gif load completely
- added gif into NSTextAttachment, but not animated
- ๅจios13็ณป็ปไธๅ ่ฝฝgifๅพ็๏ผๆดๅผ ๅพ็ไผๅๆ็ฐ่ฒ
- memeory use 500MB
- Support of SwiftPM
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftgif.