{ "id": "63703", "key": "TIMOB-3071", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "12097", "description": "", "name": "Sprint 2012-05", "archived": true, "released": true, "releaseDate": "2012-03-11" }, { "id": "12593", "name": "Release 2.0.0", "archived": false, "released": true, "releaseDate": "2012-03-30" }, { "id": "13270", "description": "Release 1.8 Service Pack 3 (CI for 1_8_X)", "name": "Release 1.8.3", "archived": true, "released": false } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2012-04-03T08:35:50.000+0000", "created": "2011-04-15T03:35:59.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "klist", "memory", "module_webview", "qe-testadded" ], "versions": [], "issuelinks": [], "assignee": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2012-04-03T08:40:13.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}

When replacing HTML elements in a webView, large images for\r\nexample, the memory used by the previous element is not release\r\ncausing an overall memory usage by the webView to rise every\r\ntime.

\r\n

There is a HD ticket with a sample code:
\r\nhttp://developer.appcelerator.com/helpdesk/view/70741

\r\n

Tested on Ti SDK 1.6 (Feb 7 2011 11:29 r160f5dc)
\r\niPhone Simulator with Xcode's Instruments Tools

{html}", "attachment": [ { "id": "18258", "filename": "webtoll.zip", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:00.000+0000", "size": 24361, "mimeType": "application/zip" } ], "flagged": false, "summary": "iOS: WebView memory is not freed", "creator": { "name": "penrique", "key": "penrique", "displayName": "Pedro Enrique", "active": false, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "penrique", "key": "penrique", "displayName": "Pedro Enrique", "active": false, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "129976", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Even MORE memory madness...

{html}", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:00.000+0000", "updated": "2011-04-15T03:36:00.000+0000" }, { "id": "129977", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Unfortunately, this is not something we have control over. I\neven tested in a native app outside of Titanium, and the web view's\nmemory footprint is its own thing. There's no API on web views for\ncontrolling memory. Worse yet, NSURLCache, which the docs implies\nthe web views would use, was not used at all, so there was nothing\nto cache.

{html}", "updateAuthor": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:01.000+0000", "updated": "2011-04-15T03:36:01.000+0000" }, { "id": "129978", "author": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Thanks for looking into it. IIRC I can't work around this by\ncreating a new webview at the moment, because the webview memory is\nnot freed when the JS object is deleted. Is this something that\nwill be addressed in 1.7?

{html}", "updateAuthor": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:01.000+0000", "updated": "2011-04-15T03:36:01.000+0000" }, { "id": "129979", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

There have been quite a few memory circular retains that have\nbeen fixed for 1.7, and you'll see this most when you have a lot of\nnon-web views and the like, especially with addEventListener.\nHowever, while the webview itself is released, the caching itself\nis not kept to the web view, but follows the beat of a different\ndrummer.

\n

Included is the test app I made. It is all native Obj-C, no\ntitanium, to make sure it wasn't just an artifact of Titanium. It\nsimply is a viewcontroller (similar to a Ti.UI.window) with a web\nview, and two buttons: One button to open up another view\ncontroller with a web view, another to try to purge the\nNSURLCache.

\n

If you play with this with the allocations monitor on it, you'll\nsee the memory jump around, sometimes almost of its own accord. One\nthing you'll notice is the memory behavior is quite different on\nsimulator as opposed to on device, especially the footprint of\nwebkit. Hitting the back does free up some memory, but not as much\nor as predictably as you expect. Worse yet, this memory size is\ncompletely unaffected by the Cache button.

{html}", "updateAuthor": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:01.000+0000", "updated": "2011-04-15T03:36:01.000+0000" }, { "id": "129980", "author": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

That's disappointing news, but I understand it's not Titanium's\nfault, and appreciate you investigating. I wonder if \nhttp://blog.techno-barje.fr/post/2010/10/04/UIWebView-secrets-part1...\nis at all related?

{html}", "updateAuthor": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:02.000+0000", "updated": "2011-04-15T03:36:02.000+0000" }, { "id": "129981", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

\"WebKitCacheModelPreferenceKey\"? Innnnteresting. I'll see what I\ncan do with this, and more importantly, if Apple considers it\nprivate API or not. (You'd think something like a string wouldn't\ntrip them off, but a long while ago, they claimed a well-documented\nPOSIX string library that's been around since the 80s was 'private\nAPI'.)

{html}", "updateAuthor": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:02.000+0000", "updated": "2011-04-15T03:36:02.000+0000" }, { "id": "129982", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Okay, an update. I didn't see much of a change in setting that\nkey, as in it still grows as it desires, although it did seem like\nit might be more conservative in grabbing memory.

\n

Either way, the NSUserDefaults is exposed in Titanium as\nTi.App.properties. So to recreate the solution proposed, use the\nfollowing JS in your app.js (NOT in the web page):

\n

\nTitanium.App.Properties.setInt('WebKitCacheModelPreferenceKey',0);

\n

I don't know if setting that NSUserDefault will help things, but\nit at least is a means to try it. Good luck.

{html}", "updateAuthor": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:02.000+0000", "updated": "2011-04-15T03:36:02.000+0000" }, { "id": "129983", "author": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Thanks for trying it. I'm really busy at the moment and won't\nhave time to play around with the code you provided for a while as\nI really need to learn some more objC first, but I appreciate you\nproviding it, and do plan to return to this issue when I have a\nchance.

{html}", "updateAuthor": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:02.000+0000", "updated": "2011-04-15T03:36:02.000+0000" }, { "id": "129984", "author": { "name": "rseagraves", "key": "rseagraves", "displayName": "Reggie Seagraves", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Due diligence has been performed and we're placing this on hold\nas an Apple bug. Will redress for 1.8.

{html}", "updateAuthor": { "name": "rseagraves", "key": "rseagraves", "displayName": "Reggie Seagraves", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:36:03.000+0000", "updated": "2011-04-15T03:36:03.000+0000" }, { "id": "185211", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Talked with Alan. Turns out this might be about something different.\r\n{quote}\r\nalanleard: bhamon: what they are trying to do is create a webview, load a sencha chart, do a toImage, and then remove the webview. They are nulling it, removing it, we can't find any references to it, but they still get retained\r\nbhamon: Okay, that's different than what I thought they wanted. If you can update the ticket with sample code, or a minimum fail case, then here's the possibilities:\r\n1) We're leaking the UIWebView or the proxy. That CAN be fixed.\r\n2) The HTML and images are still being cached by Apple, despite the UIWebView having gone away. That CANNOT be fixed.\r\nI was thinking they were talking about the latter, not the former.\r\n{quote}", "updateAuthor": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-03-06T12:21:17.000+0000", "updated": "2012-03-06T12:21:17.000+0000" }, { "id": "185215", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Okay, verified. The leak DOES happen in 1.8.2GA, but does NOT happen in CI (As of March 6th) so we're going to mark this fixed, since it has been fixed, possibly as a side-effect of some other commit, and will be in 1.9.", "updateAuthor": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-03-06T13:08:55.000+0000", "updated": "2012-03-06T13:08:55.000+0000" }, { "id": "185365", "author": { "name": "wluu", "key": "wluu", "displayName": "Wilson Luu", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing bug. Verified TiUIWebView object is being released on:\r\n\r\nSDK build: 2.0.0.v20120307090205\r\nTitanium Studio, build: 1.0.9.201202141208\r\nxcode: 4.2\r\nDevice: iphone 3GS (4.3)", "updateAuthor": { "name": "wluu", "key": "wluu", "displayName": "Wilson Luu", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2012-03-07T10:28:57.000+0000", "updated": "2012-03-07T10:28:57.000+0000" }, { "id": "189628", "author": { "name": "srahim", "key": "srahim", "displayName": "Sabil Rahim", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Reopening to place the Release 1.8.3 tag", "updateAuthor": { "name": "srahim", "key": "srahim", "displayName": "Sabil Rahim", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-04-03T08:35:38.000+0000", "updated": "2012-04-03T08:35:38.000+0000" } ], "maxResults": 16, "total": 16, "startAt": 0 } } }