{"action":"created","issue":{"url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/issues/3051","labels_url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/issues/3051/labels{/name}","comments_url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/issues/3051/comments","events_url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/issues/3051/events","html_url":"https://github.com/AnalyticalGraphicsInc/cesium/pull/3051","id":109000233,"number":3051,"title":"Memory tweaks","user":{"login":"mramato","id":1495196,"avatar_url":"https://avatars.githubusercontent.com/u/1495196?v=3","gravatar_id":"","url":"https://api.github.com/users/mramato","html_url":"https://github.com/mramato","followers_url":"https://api.github.com/users/mramato/followers","following_url":"https://api.github.com/users/mramato/following{/other_user}","gists_url":"https://api.github.com/users/mramato/gists{/gist_id}","starred_url":"https://api.github.com/users/mramato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mramato/subscriptions","organizations_url":"https://api.github.com/users/mramato/orgs","repos_url":"https://api.github.com/users/mramato/repos","events_url":"https://api.github.com/users/mramato/events{/privacy}","received_events_url":"https://api.github.com/users/mramato/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-30T02:05:06Z","updated_at":"2015-10-01T13:54:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/pulls/3051","html_url":"https://github.com/AnalyticalGraphicsInc/cesium/pull/3051","diff_url":"https://github.com/AnalyticalGraphicsInc/cesium/pull/3051.diff","patch_url":"https://github.com/AnalyticalGraphicsInc/cesium/pull/3051.patch"},"body":"@shunter you might have some thoughts on this.  I'd like this in 1.14 unless there's a good reason to hold off.\r\n\r\n1. Have `AssociativeArray.remove` actually delete the key from the object hash instead of just setting it to undefined, avoiding unbounded object growth.\r\n\r\n2. If Entity geometry was removed and a geometry of the same type was never re-added back, the destroyed Primitive instance would remain in a closure, causing any JavaScript objects referenced by the Primitive to hang around, in the case of entities, this was the array of instance ids, which could be fairly large.\r\n\r\n3. In order to reduce the change of 2 being a problem in other cases, I marked additional properties as undefined in `Primitive.destroy` to avoid objects hanging around after it is called even if the primitive itself is still inside of a closure.\r\n\r\nI originally experimented with the idea of modifying `destroyObject` to more thoroughly clean up properties by setting them to undefined, but our use of ES5 properties makes this impossible.\r\n\r\nOriginally discussed [on the forum](https://groups.google.com/d/msg/cesium-dev/QkTpzAHZ5bA/R_g8fC75BQAJ).\r\n\r\nHere's some code to test and verify the memory is being released.  Add and remove the entities and then take a Heap snapshot and verify that no Primitive or Entity objects are in the heap.  When you run this in master, there will be 1000 Entities and a Primitive stuck there.\r\n\r\n```javascript\r\nvar viewer = new Cesium.Viewer('cesiumContainer');\r\nvar testDataSource = new Cesium.CustomDataSource('test');\r\nviewer.dataSources.add(testDataSource);\r\n\r\nvar createQuantity = 1000;\r\nvar created = 0;\r\nvar deleted = 0;\r\n\r\n// Add entities\r\nfunction addEntities(){\r\n    for (var i = created; i < (created + createQuantity); i++) {\r\n        var entity = testDataSource.entities.getById(i);\r\n        var lng = -80.12;\r\n        var lat = 25.46;\r\n        var name = 'test' + i;\r\n        var type = 'type' + i;\r\n        var description = ' test description words ' + i +\r\n                          ' test description words ' + i +\r\n                          ' test description words ' + i +\r\n                          ' test description words ' + i +\r\n                          ' test description words ' + i;\r\n\r\n        // If no heat dot found, create it\r\n        if (typeof entity === 'undefined') {\r\n            entity = testDataSource.entities.add({\r\n                id: i,\r\n                name: name,\r\n                entityType: type,\r\n                description: description,\r\n                rectangle: {\r\n                    coordinates: Cesium.Rectangle.fromDegrees(lng - 0.0001, lat - 0.0001,\r\n                                                              lng + 0.0001, lat + 0.0001),\r\n                    material: Cesium.Color.WHITE.withAlpha(0.5),\r\n                    extrudedHeight: 100\r\n                }\r\n            });\r\n        }\r\n    }\r\n    created = created + createQuantity;\r\n    viewer.zoomTo(testDataSource);\r\n}\r\n\r\n// Remove all\r\nfunction removeAllEntities(){\r\n    for (var i = 0; i < testDataSource.entities.values.length; i++) {\r\n        var entity = testDataSource.entities.values[i];\r\n        testDataSource.entities.remove(entity);\r\n        deleted += 1;\r\n        i--;\r\n    }\r\n}\r\n\r\nSandcastle.addToolbarButton('Add ' + createQuantity + ' Entities', function() {\r\n    addEntities();\r\n});\r\n\r\nSandcastle.addToolbarButton('Remove All Entities', function() {\r\n    removeAllEntities();\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/issues/comments/144732281","html_url":"https://github.com/AnalyticalGraphicsInc/cesium/pull/3051#issuecomment-144732281","issue_url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/issues/3051","id":144732281,"user":{"login":"mramato","id":1495196,"avatar_url":"https://avatars.githubusercontent.com/u/1495196?v=3","gravatar_id":"","url":"https://api.github.com/users/mramato","html_url":"https://github.com/mramato","followers_url":"https://api.github.com/users/mramato/followers","following_url":"https://api.github.com/users/mramato/following{/other_user}","gists_url":"https://api.github.com/users/mramato/gists{/gist_id}","starred_url":"https://api.github.com/users/mramato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mramato/subscriptions","organizations_url":"https://api.github.com/users/mramato/orgs","repos_url":"https://api.github.com/users/mramato/repos","events_url":"https://api.github.com/users/mramato/events{/privacy}","received_events_url":"https://api.github.com/users/mramato/received_events","type":"User","site_admin":false},"created_at":"2015-10-01T13:54:05Z","updated_at":"2015-10-01T13:54:05Z","body":"Bump to try and get this into 1.14 later today."}}