{ "id": "85868", "key": "TIMOB-7523", "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": "12095", "description": "", "name": "Sprint 2012-03", "archived": true, "released": true, "releaseDate": "2012-02-12" }, { "id": "12593", "name": "Release 2.0.0", "archived": false, "released": true, "releaseDate": "2012-03-30" }, { "id": "13070", "description": "Release 1.8 Service Pack 2", "name": "Release 1.8.2", "archived": true, "released": true, "releaseDate": "2012-02-29" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2012-02-14T23:29:01.000+0000", "created": "2012-02-02T13:59:50.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [], "versions": [ { "id": "12580", "description": "Dual Runtime 1.8.0", "name": "Release 1.8.0.1", "archived": true, "released": true, "releaseDate": "2011-12-22" } ], "issuelinks": [ { "id": "15111", "type": { "id": "10020", "name": "Depends", "inward": "is dependent of", "outward": "depends on" }, "outwardIssue": { "id": "62174", "key": "TIMOB-1542", "fields": { "summary": "iOS: 'pause' and 'resume' events don't seem to fire correctly", "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" } }, "priority": { "name": "Critical", "id": "1" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2012-02-14T23:29:01.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": "Throughout the code there are functions which need to be performed on the main thread, but still return a value (mostly in Contacts and Media, although there may be others). Now that we have blocks, we can instead use local variables with the {{__block}} specifier and {{TiThreadPerformOnMainThread}} to clean this up. Using the return cache leads (and has always led to) overretaining memory.\r\n\r\nBlain's fix for TIMOB-1542 demonstrates a reasonable pattern for this, but rather than checking `[NSThread isMainThread]` and then calling back out to the function, we should instead be putting main thread critical sections within the block itself, i.e.\r\n\r\n{code}\r\n-(id)getPropertyFromMainThread\r\n{\r\n __block id result = nil;\r\n TiThreadPerformOnMainThread(^{\r\n // Critical code to get value for 'result' here...\r\n [result retain];\r\n }, YES);\r\n return [result autorelease];\r\n}\r\n{code}\r\n\r\nNote the {{retain/autorelease}} pattern being necessary, as if the block is performed on the main thread, it sets up its own autorelease pool and as a result may point back to a bad memory block.", "attachment": [], "flagged": false, "summary": "iOS: Use blocks and remove \"return caches\" from code", "creator": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "182322", "author": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "The pull request for 1542 will include the commits fixing this bug as well.", "updateAuthor": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-02-07T17:23:07.000+0000", "updated": "2012-02-07T17:23:07.000+0000" }, { "id": "183035", "author": { "name": "thomashuelbert", "key": "thomashuelbert", "displayName": "Thomas Huelbert", "active": true, "timeZone": "America/Los_Angeles" }, "body": "no way for qe to confirm, closing", "updateAuthor": { "name": "thomashuelbert", "key": "thomashuelbert", "displayName": "Thomas Huelbert", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-02-14T08:53:51.000+0000", "updated": "2012-02-14T08:53:51.000+0000" } ], "maxResults": 2, "total": 2, "startAt": 0 } } }