# Memory Leak on iOS

**URL:** https://forums.fusetools.com/t/memory-leak-on-ios/4560
**Category:** Bug Reports
**Created:** [February 28, 2016, 11:16pm UTC](https://forums.fusetools.com/t/memory-leak-on-ios/4560 "2016-02-28T23:16:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Marcelo\_Alves](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/marcelo_alves/32/86_2.png) [@Marcelo\_Alves](https://forums.fusetools.com/u/Marcelo_Alves)
#### Post date: [February 28, 2016, 11:16pm UTC](https://forums.fusetools.com/t/memory-leak-on-ios/4560/1 "2016-02-28T23:16:17Z")

</div>

The code below is _almost_ a minimal case (yay!) that exhibits the issue. It display 3 images from a “circular buffer”. Tapping any picture remove the first image and adds a new one at the end of the array.

The problem is does never release the memory used by the panel (or images). Worse, it keeps allocating memory. (Again, this is a minimal case, the memory increase is about 150KiB per tap, but in the real app it is +1MB per page)

Also, the CPU usage is pretty high. On an iPhone 6+, the CPU usage is about 10% when idle.

```auto
<App Theme="Basic">
    <JavaScript>
        var Observable = require("FuseJS/Observable");

        var URL = "https://api.flickr.com/services/feeds/photos_public.gne?format=json&quot;;

        var allItems = Observable();
        var visibleItems = Observable();

        function log(what) {
            debug_log(what);
        }

        function downloadFeed() {
            log("Downloading...");

            fetch(URL, {
                method: "GET",
                headers: {"Content-type": "application/json"}
            }).then(function(response) {
                return response.text();
            }).then(function(fakeJSON) {
                log("Removing weird function enclosure...");
                var r = /jsonFlickrFeed(({[^]*}))/m;
                var match = r.exec(fakeJSON);
                var json = JSON.parse(match[1]).items;

                log("Adding items...");
                json.map(function(i) {
                    allItems.add(i);
                });

                fillVisibleItems();
            });
        }

        var index = 0;
        var numberOfVisibleItems = 3;

        function removeItem() {
            visibleItems.removeAt(0);
            fillVisibleItems();
        }

        function fillVisibleItems() {
            while (visibleItems.length < numberOfVisibleItems) {
                if (index >= allItems.length) {
                    index = 0;
                }

                visibleItems.add(allItems.getAt(index));
                index += 1;
            }
        }

        module.exports = {
            items: visibleItems,
            RemoveItem: removeItem,
        }

        downloadFeed();
    </JavaScript>

    <Panel>
        <ScrollView>
            <StackPanel Clicked="{RemoveItem}">
                <Each Items="{items}">
                    <Image Url="{media.m}" Margin="0" StretchMode="Uniform" />
                </Each>
            </StackPanel>
        </ScrollView>
    </Panel>
</App>

```

---

<div class="post-metadata">

### Author: ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)
#### Post date: [February 29, 2016, 6:11am UTC](https://forums.fusetools.com/t/memory-leak-on-ios/4560/2 "2016-02-29T06:11:33Z")

</div>

Woah! Thanks for the test case.

We will be investigating this immediately.

---

<div class="post-metadata">

### Author: ![kusma](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kusma/32/595_2.png) [@kusma](https://forums.fusetools.com/u/kusma)
#### Post date: [May 24, 2016, 1:55pm UTC](https://forums.fusetools.com/t/memory-leak-on-ios/4560/3 "2016-05-24T13:55:55Z")

</div>

I’m sorry for the late reply, but I cannot reproduce this issue any more. The lifetime of JavaScriptCore objects has been entirely rewritten since this issue was reported, so I assume it’s no longer the case. Please let me know if I somehow misdiagnosed, and you still suffer from this.
