{"action":"created","issue":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/1280","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/1280/labels{/name}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/1280/comments","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/1280/events","html_url":"https://github.com/mapbox/mapbox-gl-native/pull/1280","id":68840663,"number":1280,"title":"[not ready] fixes #1267: properly break reference cycle with tile data & style","user":{"login":"incanus","id":17722,"avatar_url":"https://avatars.githubusercontent.com/u/17722?v=3","gravatar_id":"","url":"https://api.github.com/users/incanus","html_url":"https://github.com/incanus","followers_url":"https://api.github.com/users/incanus/followers","following_url":"https://api.github.com/users/incanus/following{/other_user}","gists_url":"https://api.github.com/users/incanus/gists{/gist_id}","starred_url":"https://api.github.com/users/incanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/incanus/subscriptions","organizations_url":"https://api.github.com/users/incanus/orgs","repos_url":"https://api.github.com/users/incanus/repos","events_url":"https://api.github.com/users/incanus/events{/privacy}","received_events_url":"https://api.github.com/users/incanus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/milestones/5","html_url":"https://github.com/mapbox/mapbox-gl-native/milestones/iOS%20Beta%201","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/milestones/5/labels","id":978852,"number":5,"title":"iOS Beta 1","description":"","creator":{"login":"incanus","id":17722,"avatar_url":"https://avatars.githubusercontent.com/u/17722?v=3","gravatar_id":"","url":"https://api.github.com/users/incanus","html_url":"https://github.com/incanus","followers_url":"https://api.github.com/users/incanus/followers","following_url":"https://api.github.com/users/incanus/following{/other_user}","gists_url":"https://api.github.com/users/incanus/gists{/gist_id}","starred_url":"https://api.github.com/users/incanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/incanus/subscriptions","organizations_url":"https://api.github.com/users/incanus/orgs","repos_url":"https://api.github.com/users/incanus/repos","events_url":"https://api.github.com/users/incanus/events{/privacy}","received_events_url":"https://api.github.com/users/incanus/received_events","type":"User","site_admin":false},"open_issues":21,"closed_issues":127,"state":"open","created_at":"2015-02-13T19:24:01Z","updated_at":"2015-04-16T04:17:30Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2015-04-16T04:17:30Z","updated_at":"2015-04-16T07:30:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/1280","html_url":"https://github.com/mapbox/mapbox-gl-native/pull/1280","diff_url":"https://github.com/mapbox/mapbox-gl-native/pull/1280.diff","patch_url":"https://github.com/mapbox/mapbox-gl-native/pull/1280.patch"},"body":""},"comment":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/comments/93665087","html_url":"https://github.com/mapbox/mapbox-gl-native/pull/1280#issuecomment-93665087","issue_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/1280","id":93665087,"user":{"login":"incanus","id":17722,"avatar_url":"https://avatars.githubusercontent.com/u/17722?v=3","gravatar_id":"","url":"https://api.github.com/users/incanus","html_url":"https://github.com/incanus","followers_url":"https://api.github.com/users/incanus/followers","following_url":"https://api.github.com/users/incanus/following{/other_user}","gists_url":"https://api.github.com/users/incanus/gists{/gist_id}","starred_url":"https://api.github.com/users/incanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/incanus/subscriptions","organizations_url":"https://api.github.com/users/incanus/orgs","repos_url":"https://api.github.com/users/incanus/repos","events_url":"https://api.github.com/users/incanus/events{/privacy}","received_events_url":"https://api.github.com/users/incanus/received_events","type":"User","site_admin":false},"created_at":"2015-04-16T07:30:05Z","updated_at":"2015-04-16T07:30:05Z","body":"Got it, finally. You are right @jfirebaugh that the problem is the `TileData` destructor never getting called. I was confused by seeing it called for viewport changes but missed that it wasn't being called for style changes. I was also confused because the `Style` destructor seemed like it always being called, but in fact it was only the initial dummy style created in `Map::reloadStyle()` before async JSON loading happens each style load and the dummy is replaced and zeros out. So the over-retained objects include the entire `Style > StyleLayer > StyleBucket > Source > TileData` chain and my initial hunch in #1267 of sources and the style being kept around was right. \r\n\r\nWhen `LiveTileData` isn't in the picture (commenting out [the annotations functionality](https://github.com/mapbox/mapbox-gl-native/blob/ed74c6e23d12a9c196d623ab1ed344c1d829fcc7/src/mbgl/style/style_parser.cpp#L40-L69) in `StyleParser`), `VectorTileData` objects are destructed properly when the style changes. `Style` releases `StyleLayer` releases `StyleBucket` releases `Source` releases `VectorTileData`, which doesn't have a hold on `Style`. Though `Source` holds `TileData` weakly (in `tile_data`), it holds `Tile` strongly (in `tiles`), and `Tile` holds `TileData` strongly (in `data`), so this is a true cyclical reference and needs this style release. \r\n\r\n![screen shot 2015-04-16 at 12 24 38 am](https://cloud.githubusercontent.com/assets/17722/7175984/fe85de22-e3ce-11e4-88ce-9404c9ebf450.png)\r\n\r\nHere you can see the dummy, then the real, style being created, then the dummy destroyed (`style  going away`), then upon application of the new style, the first real style destroyed (`style asset://styles/ going away`), and then the whole graph after it (including all layers, then sources, then their live and vector tiles — total cleanup). \r\n\r\nWhen annotation support was introduced with the bug of not releasing `Style` from `LiveTileData` when no annotations existed (startup condition), we'd get the reference cycle which would result in neither `LiveTileData` nor `VectorTileData` being released since the old style was over-retained (only on the \"`LiveTileData` side\", which of course was enough). \r\n\r\n![screen shot 2015-04-16 at 12 26 34 am](https://cloud.githubusercontent.com/assets/17722/7176003/47bb2048-e3cf-11e4-9b1f-ef0bb7eba850.png)\r\n\r\nHere you only see the dummy style pre-async load created each time, but no real styles nor tiles ever destroyed. \r\n\r\nThis is good to go **and** I'm satisfied that I know why. Going to merge and get back to #1255. "}}