I've been testing around a lot of open-source animated-gif libraries to load GIF
files into our Swift
project.
Most of them claim to be high-performance libraries, however, whenever I load an animated gif my application uses around 8MB of memory.
The problem is that this dedicated memory space seems to never be released. We can see it growing linearly:
And it makes me wonder if I'm doing the right thing here. Is this behavior correct, or is it potentially bad for the user?
The main reason why your GIFs load so slowly is likely because you have too many frames in the GIF. Next time, delete one frame for every two that you use.
Photos can be up to 5MB, animated GIFs can be up to 5MB on mobile, and up to 15MB on web. Supported image types are GIF, JPEG, and PNG files.
To change the speed of a GIF in Photoshop, first, open your GIF file, then go to Window > Timeline. In the Timeline panel, click the first frame, hold Shift, then click the last frame to select the whole GIF. Now click the frame delay setting and choose a new time to speed up or slow down your GIF.
How long can an animated GIF be? The same, there is no restriction on the length of a GIF. While some platforms have ruled it. (Such as, GIPHY suggests uploading a GIF no more than 6 seconds and it won't accept a 15 seconds plus GIF.)
you would need to remove the Gif images manually for them to get cleared from the memory.
Example: gifViwer can be your Gif Viewer in this example
self.gifViewer.removeFromSuperview()
self.gifViewer = nil
if you had to assign a delegate then you can also add
self.gifViewer.Delegate = nil
Note: you need to run this when the viewControler
is being completely unloaded as the app will start looking for gifViewer
in the view while it has been removed. if you need to clear the gif image from the memory without unloading the view then I suggest to use the steps above and then adding the view to the superView programatically. this is not going to work with the interface designer and IBOutlets
let gifViewer = yourGifViewerClass(frame: CGRect(x: 20, y: 20, width: self.view / 2, height: self.view / 2))
// setup your gifViewer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With