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.
<App Theme="Basic">
<JavaScript>
var Observable = require("FuseJS/Observable");
var URL = "https://api.flickr.com/services/feeds/photos_public.gne?format=json";
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>