Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3115] iOS: Expose didReceiveMemoryWarning Event to JS

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-03-03T20:40:25.000+0000
Affected Version/sRelease 1.7.0
Fix Version/s2014 Sprint 05, 2014 Sprint 05 API, Release 3.2.3, Release 3.3.0
ComponentsiOS
Labels3.2.1, feature, ios, module_app, qe-testadded, rplist, triage
ReporterDawson Toth
AssigneePedro Enrique
Created2011-04-15T03:37:18.000+0000
Updated2014-03-19T11:13:08.000+0000

Description

Problem

Assume you have a web view. When Titanium receives a memory warning, it cleans up the web view, releasing its resources. Now if the app is resumed, the web view will be blank. But a pure JS app has no way of knowing this has happened or handling this event, because we do not expose the didReceiveMemoryWarning event to the JS side of things.

Solution

Add a global event, "didReceiveMemoryWarning", so that developers can handle this scenario.

Workaround

Create an iOS module that fires this event for the JS to consume.

Associated Helpdesk Ticket

http://developer.appcelerator.com/helpdesk/view/71071

Comments

  1. Hans Knöchel 2013-08-30

    *PUSH* Could someone please address this problem? It needs to be a new EventListener that handles this event. Thank you!
  2. Ingo Muschenetz 2013-08-30

    [~hansknoechel] We are relatively packed for our next major feature release in December, but I have tentatively placed it in the following release.
  3. Hans Knöchel 2013-08-30

    Thank you! It has been noticed, all good!
  4. Pedro Enrique 2013-12-03

    PR pending: https://github.com/appcelerator/titanium_mobile/pull/5054
  5. Vishal Duggal 2014-03-03

    PR merged into master
  6. Vishal Duggal 2014-03-18

    Backport to 3_2_X https://github.com/appcelerator/titanium_mobile/pull/5490
  7. Paras Mishra 2014-03-19

    Verified that 'didRecieveMemoryWarning' is exposed to JS as 'memorywarning' event. Testapp used to verify:
       
       var win1 = Titanium.UI.createWindow({  
           title:'Home Window',
           backgroundColor:'#fff'
       });
       var input = Ti.UI.createTextField({
       	hintText:'Enter number of rows to be generated',
       	top:20
       });
       var but = Ti.UI.createButton({
       	title:'Check Available memory',
       	top: 50
       });
       var but1 = Ti.UI.createButton({
       	title:'add '+input.getValue()+ 'table rows',
       	top: 80
       });
       
       var tableData = [];
       but.addEventListener('click',function(e){
       	alert(Titanium.Platform.getAvailableMemory() );
       });
       but1.addEventListener('click',function(e){
       	createRow();
       });
       
       var table = Ti.UI.createTableView({ 
       	objName: 'table',
       	top: 150
       	 });
       	 
       
       function createRow(){
       	for(var i = 0;i<input.getValue();i++){
       	var row = Ti.UI.createTableViewRow({
           className: 'row',
           objName: 'row'+i,
           touchEnabled: true,
           //height: 100
         });
         var label = Ti.UI.createLabel({
           backgroundColor:'red',
           color: 'white',
           objName: 'label',
           text: 'Titanium'+i,
           touchEnabled: false,
           left: 0,
       
         });
         row.add(label);
         tableData.push(row);
       	}
       	table.setData(tableData);
       }
       
       	Titanium.App.addEventListener('memorywarning',function(e){
       		alert("Low Memory detected !!");
       	});
       
       win1.add(input);
       win1.add(but);
       win1.add(but1);
       win1.add(table);
       win1.open();
       
       
    To verify: 1. Enter rows around 10000 to generate and check memory to be below 50 mb. 2. An alert should popup when memorywarning event is occured as "low Memory detected !!" Environment used: Device : iPod touch 1 5th Generation, iOS version: 7.0.4 SDK: 3.2.3.v20140318131613 CLI version : 3.2.1 OS : MAC OSX 10.9 Alloy: 1.3.1 ACS: 1.0.14 npm:1.3.2 Appcelerator Studio, build: 3.2.3.201403181115 titanium-code-processor: 1.1.0 XCode : 5.1

JSON Source