Vivoactive HR "switchToView" memory leak !!

Former Member
Former Member
I've discovered memory leak of main functionality on Vivoactive HR device. FW 3.30

The problem can be seen on video:
https://www.youtube.com/watch?v=To3fIsjdQw4

There are two simple pages. Memory leak occurs when I try to switch between pages by metho

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. Ive prepared simple watchapp example to reproduce this issue:

using Toybox.Application as App;
using Toybox.WatchUi as Ui;


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();
}
}


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);
}
}

}


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);
}
}


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);
}
}


<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="www.garmin.com/.../connectiq" version="3">
<iq:application entry="test_leakApp" id="6854DB5F409A47869D64B800F18A9D13" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="2.1.1" name="@Strings.AppName" type="watch-app">

<iq:products>
<iq:product id="vivoactive_hr"/>
</iq:products>

<iq:permissions>
</iq:permissions>

<iq:languages/>

</iq:application>
</iq:manifest>