The problem can be seen on youtube:
https://youtu.be/To3fIsjdQw4
There are two simple Pages (Views). Problem was when I tried switch page by following methods:
function SwitchToPage(newIndex) {
_index = newIndex;
if (_index == 0) {
Ui.switchToView(new MainPage(), new MainDelegate(_index), Ui.SLIDE_LEFT);
} else {
Ui.switchToView(new ExtraInfoPage(), new MainDelegate(_index), Ui.SLIDE_LEFT);
}
}
So .I've prepared simple test application to reproduce it:
Testleak.mc
using Toybox.Application as App;
using Toybox.WatchUi as Ui;
class test_leakApp extends App.AppBase {
function initialize() {
AppBase.initialize();
}
function getInitialView() {
return [ new MainPage(), new MainDelegate(0) ];
}
function mainTimerHandler() {
Ui.requestUpdate();
}
}
MainPage.mc
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
class MainPage extends Ui.View {
function initialize() {
View.initialize();
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.clear();
var stats = Sys.getSystemStats();
dc.drawText(60, 20, Gfx.FONT_SYSTEM_MEDIUM, "Mem: " + stats.usedMemory.format( "%d" ), Gfx.TEXT_JUSTIFY_CENTER);
}
}
ExtraInfoPage.mc
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
class ExtraInfoPage extends Ui.View {
function initialize() {
View.initialize();
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.clear();
var stats = Sys.getSystemStats();
dc.drawText(60, 20, Gfx.FONT_SYSTEM_MEDIUM, "Mem: " + stats.usedMemory.format( "%d" ), Gfx.TEXT_JUSTIFY_CENTER);
var center = (dc.getWidth().toFloat() / 2.toFloat()).toNumber();
dc.setPenWidth(3);
dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT);
dc.drawRoundedRectangle(center, 58, 3, 140, 5);
}
}
MainDelegate.mc
using Toybox.WatchUi as Ui;
const NO_PAGES = 2;
class MainDelegate extends Ui.BehaviorDelegate {
var _index = 0;
function initialize(idx) {
BehaviorDelegate.initialize();
_index = idx;
}
function onNextPage() {
var newIndex = _index + 1;
if (newIndex >= NO_PAGES) {
newIndex = 0;
}
SwitchToPage(newIndex);
return true;
}
function onPreviousPage() {
var newIndex = _index - 1;
if (newIndex < 0) {
newIndex = NO_PAGES - 1;
}
SwitchToPage(newIndex);
return true;
}
function SwitchToPage(newIndex) {
_index = newIndex;
if (_index == 0) {
Ui.switchToView(new MainPage(), new MainDelegate(_index), Ui.SLIDE_LEFT);
} else {
Ui.switchToView(new ExtraInfoPage(), new MainDelegate(_index), Ui.SLIDE_LEFT);
}
}
}
Regards