Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Garbage collection in platform services in the WRT 1.1 environment

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Tested with
Devices(s): All devices using Browser 7.1
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject
Created: User:Kbwiki (02 Nov 2009)
Last edited: lpvalente (26 Jul 2014)


Contents

Overview

The garbage collection of JavaScript service objects has recently changed. This change was done to improve performance and memory efficiency. Even though JavaScript objects have a small memory footprint, the memory consumed by underlaying native objects must be released.

Description

Previously, bindings to native code protected the JavaScript objects obtained through platform services. The current implementation does not protect objects anymore, and one must be careful not to let them fall out of the scope.

How to reproduce

The following code shows the situation that must be avoided. The correct way is included in the code comments.

 var media=null;  
var garbage=null;
 
function init(){
var so = device.getServiceObject("Service.MediaManagement", "IDataSource");
 
//the right way
//this.media = so;
 
//this worked on previous releases
this.media = so.IDataSource;
 
garbage = new Array();
}
 
function getImages(){
//ensure that garbage collector runs and invalidates so
for(var i=0; i< 50000; i++){
garbage[i]= new Object();
}
 
try {
//getList() is no longer defined
alert("Media: "+ typeof media +" Media.getList(): "+typeof media.GetList);
 
//the right way
//var result = media.IDataSource.GetList(criteria, callback);
 
//does not work anymore since so falls out of scope and becomes invalid
//var result = media.GetList(criteria, callback);
}
catch (e) {
alert ("getImages: " + e);
}
}

Solution

Make sure that reusable service objects and their parents do not fall out of the scope. If they fall out of the scope, the garbage collector will clean them up.

This page was last modified on 26 July 2014, at 23:26.
128 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×