Memory management/cloud image storage by Flutter

Asked

Viewed 228 times

-1

I recently started developing an App on Flutter and am trying to understand how it uses device memory/storage in relation to cloud-hosted images.

To better contextualize is a Market App, the consumption of the images we are using the cosmos API (https://cosmos.bluesoft.com.br/api), that returns a link with the image hosting by them and the Flutter widget would be this (https://api.flutter.dev/flutter/widgets/Image/Image.network.html).

Requesting Flutter will cause the image information to be cached in the application, thus increasing memory/space consumption while the App is open and when finished clearing the cache of these requests?

In addition there is a better image extension suitable for use in flutter applications because of this consumption?

Thank you!

1 answer

0

Looking at the documentation included in the question, we see in the builder network widget Image the following description:

All network images are cached regardless of HTTP headers. If cacheWidth or cacheHeight are provided, it indicates to the engine that the image should be decoded at the specified size. The image will be rendered to the constraints of the layout or width and height regardless of These Parameters. These Parameters are primarily intended to reduce the memory Usage of Imagecache.

All images are curled independent of the connection headers. If the cache width or height parameters are reported, it will be used for the Flutter engine that the image should be decoded in this size. This does not influence the display width/height in the layout. These parameters are used to reduce memory usage of Image cache (Free translation)

So we see in this piece of documentation that, if desired, you can cache a smaller resolution of this image. It is a point of customization if desired.

About the class Imagecache we see that:

Implements a least-recently-used cache of up to 1000 images, and up to 100 MB. The Maximum size can be adjusted using maximumSize and maximumSizeBytes.

Implements a cache that by default has a size of 1000 images and up to 100MB. These values can be changed using the reported parameters.

With that we deduce that you can customize your cache to a specified maximum size, if you prefer. This will not grow indefinitely or without control, regardless of the size of your application. (If you want you can also clear the current cache with the method clear.)

Worth making clear, that the cache specified in these documents refers to a cache made for the image display, and not for getting the image itself. This is automatically managed by the class Imageprovider. Even saved images locally are stored in this cache. It is a matter of saving the re-painting/re-drawing of those images. I believe it is only necessary to worry about this in exceptional cases, such as many images being displayed simultaneously (to generate a mosaic, for example).

Therefore, I believe that the chosen extension will not influence much. About the file size, the most commonly used ones are already well optimized for use by the Web. I refer to JPG and PNG formats.

If you want to use local cache of images hosted in the cloud you can take a read here. This way the download of these images will not be necessary after the first time, including for among multiple executions of your application. This is not done by default in Flutter and to do so should be used a bundle.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.