Search code examples
imageandroid-imagenativescript

NativeScript working with images efficiently


I’m developing an application that should display all the images you have in external storage. It’s an app just for a researching work not as a final product.

The problem I have is that the app shows me a few images until I have an Out of Memory error.

There is a way to deal with images efficiently? or avoid that error?

I post here my main-page.xml

<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="onPageLoaded">
<ListView id="listview" items="{{ myItems }}">
            <ListView.itemTemplate>
                <StackLayout orientation="horizontal">
                <Image src="{{ src }}" class="imagebox" stretch="none" />
                </StackLayout>
            </ListView.itemTemplate>
        </ListView>
</Page>

I have an array where I put each image path.


Solution

  • Yep, one of the many frustrations for developers of native apps (specifically on Android handling memory with images). Luckily the NativeScript team has packaged Fresco (a Facebook library for memory management) https://github.com/NativeScript/nativescript-fresco and a community member has packaged Picasso (Square library) here : https://github.com/triniwiz/nativescript-image-cache-it

    Using one of those libraries should resolve any issues with memory management/images on Android.