{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/WebDriverAgent/issues/896","repository_url":"https://api.github.com/repos/facebook/WebDriverAgent","labels_url":"https://api.github.com/repos/facebook/WebDriverAgent/issues/896/labels{/name}","comments_url":"https://api.github.com/repos/facebook/WebDriverAgent/issues/896/comments","events_url":"https://api.github.com/repos/facebook/WebDriverAgent/issues/896/events","html_url":"https://github.com/facebook/WebDriverAgent/pull/896","id":309092227,"number":896,"title":"Support getting the element cache size, clearing the element cache ","user":{"login":"qmfrederik","id":9918129,"avatar_url":"https://avatars0.githubusercontent.com/u/9918129?v=4","gravatar_id":"","url":"https://api.github.com/users/qmfrederik","html_url":"https://github.com/qmfrederik","followers_url":"https://api.github.com/users/qmfrederik/followers","following_url":"https://api.github.com/users/qmfrederik/following{/other_user}","gists_url":"https://api.github.com/users/qmfrederik/gists{/gist_id}","starred_url":"https://api.github.com/users/qmfrederik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmfrederik/subscriptions","organizations_url":"https://api.github.com/users/qmfrederik/orgs","repos_url":"https://api.github.com/users/qmfrederik/repos","events_url":"https://api.github.com/users/qmfrederik/events{/privacy}","received_events_url":"https://api.github.com/users/qmfrederik/received_events","type":"User","site_admin":false},"labels":[{"id":255940325,"url":"https://api.github.com/repos/facebook/WebDriverAgent/labels/CLA%20Signed","name":"CLA Signed","color":"009900","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-03-27T18:56:50Z","updated_at":"2018-03-27T20:12:20Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/facebook/WebDriverAgent/pulls/896","html_url":"https://github.com/facebook/WebDriverAgent/pull/896","diff_url":"https://github.com/facebook/WebDriverAgent/pull/896.diff","patch_url":"https://github.com/facebook/WebDriverAgent/pull/896.patch"},"body":"Every time a user finds an element using the `element` or `elements` route, a new `XCUIElement` object is added to the session cache. The elements are never removed from the cache.\r\n\r\nA very naïve script which goes to the home screen and queries for the 'Phone' element 1000 times in a row, will cause memory consumption (as measured by Xcode) of the WebDriverAgent to grow to approximately 126 MB. Net, it appears that every `XCUIElement` object consumes about 100KB of memory.\r\n\r\nFor sessions which persist for a long period of time (say, 30 minutes or more), this can eventually lead to an out of memory situation in which the WebDriverAgent crashes.\r\n\r\nThis PR tries to provide an 'escape hatch' for applications which want long-running sessions, by allowing them to:\r\n- query the amount of elements in the cache\r\n- clear the element cache\r\nby adding two custom routes.\r\n\r\nWe're looking at other approaches to keep the cache size under control as well - e.g. by checking the element cache for duplicates and adding an option to remove 'stale' elements (elements which no longer exist); we'll try to submit PRs for that as well.\r\n\r\nAs usual, let me know what you think & happy to discuss further."},"comment":{"url":"https://api.github.com/repos/facebook/WebDriverAgent/issues/comments/376659046","html_url":"https://github.com/facebook/WebDriverAgent/pull/896#issuecomment-376659046","issue_url":"https://api.github.com/repos/facebook/WebDriverAgent/issues/896","id":376659046,"user":{"login":"mykola-mokhnach","id":7767781,"avatar_url":"https://avatars1.githubusercontent.com/u/7767781?v=4","gravatar_id":"","url":"https://api.github.com/users/mykola-mokhnach","html_url":"https://github.com/mykola-mokhnach","followers_url":"https://api.github.com/users/mykola-mokhnach/followers","following_url":"https://api.github.com/users/mykola-mokhnach/following{/other_user}","gists_url":"https://api.github.com/users/mykola-mokhnach/gists{/gist_id}","starred_url":"https://api.github.com/users/mykola-mokhnach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mykola-mokhnach/subscriptions","organizations_url":"https://api.github.com/users/mykola-mokhnach/orgs","repos_url":"https://api.github.com/users/mykola-mokhnach/repos","events_url":"https://api.github.com/users/mykola-mokhnach/events{/privacy}","received_events_url":"https://api.github.com/users/mykola-mokhnach/received_events","type":"User","site_admin":false},"created_at":"2018-03-27T20:12:20Z","updated_at":"2018-03-27T20:12:20Z","author_association":"CONTRIBUTOR","body":"Of course. Just add unit and/or integration testing there"}}
{"actor":{"display_login":"mykola-mokhnach"}}