{"action":"created","comment":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/60611902","id":60611902,"diff_hunk":"@@ -119,6 +119,73 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {\n     return highestResource;\n }\n \n+ScriptableResource::ScriptableResource(const QUrl& url) :\n+    QObject(nullptr),\n+    _url(url) {}\n+\n+void ScriptableResource::release() {\n+    disconnectHelper();\n+    _resource.reset();\n+}\n+\n+void ScriptableResource::updateMemoryCost(const QObject* engine) {\n+    if (_resource && !_resource->isInScript()) {\n+        _resource->setInScript(true);\n+        connect(_resource.data(), SIGNAL(updateSize(qint64)), engine, SLOT(updateMemoryCost(qint64)));\n+    }\n+}\n+\n+void ScriptableResource::finished(bool success) {\n+    disconnectHelper();\n+\n+    _isLoaded = true;\n+    _isFailed = !success;\n+\n+    if (_isFailed) {\n+        emit failedChanged(_isFailed);\n+    }\n+    emit loadedChanged(_isLoaded);\n+}\n+\n+void ScriptableResource::disconnectHelper() {\n+    if (_progressConnection) {\n+        disconnect(_progressConnection);\n+    }\n+    if (_finishedConnection) {\n+        disconnect(_finishedConnection);\n+    }\n+}\n+\n+ScriptableResource* ResourceCache::prefetch(const QUrl& url, void* extra) {\n+    auto result = new ScriptableResource(url);\n+\n+    if (QThread::currentThread() != thread()) {\n+        // Must be called in thread to ensure getResource returns a valid pointer\n+        QMetaObject::invokeMethod(this, \"prefetch\", Qt::BlockingQueuedConnection,\n+            Q_RETURN_ARG(ScriptableResource*, result), Q_ARG(QUrl, url));\n+        return result;\n+    }\n+\n+\n+    auto resource = getResource(url, QUrl(), false, extra);\n+    result->_resource = resource;\n+    result->setObjectName(url.toString());\n+\n+    result->_resource = resource;\n+    if (resource->isLoaded()) {\n+        result->finished(!resource->_failedToLoad);\n+    } else {\n+        result->_progressConnection = connect(\n+            resource.data(), &Resource::onProgress,\n+            result, &ScriptableResource::progressChanged);\n+        result->_finishedConnection = connect(\n+            resource.data(), &Resource::finished,\n+            result, &ScriptableResource::finished);\n+    }\n+\n+    return result;\n+}","path":"libraries/networking/src/ResourceCache.cpp","position":69,"original_position":69,"commit_id":"713fc44ec5738789dbca9973ddc539b44ce0de82","original_commit_id":"713fc44ec5738789dbca9973ddc539b44ce0de82","user":{"login":"AndrewMeadows","id":2186405,"avatar_url":"https://avatars.githubusercontent.com/u/2186405?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewMeadows","html_url":"https://github.com/AndrewMeadows","followers_url":"https://api.github.com/users/AndrewMeadows/followers","following_url":"https://api.github.com/users/AndrewMeadows/following{/other_user}","gists_url":"https://api.github.com/users/AndrewMeadows/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewMeadows/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewMeadows/subscriptions","organizations_url":"https://api.github.com/users/AndrewMeadows/orgs","repos_url":"https://api.github.com/users/AndrewMeadows/repos","events_url":"https://api.github.com/users/AndrewMeadows/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewMeadows/received_events","type":"User","site_admin":false},"body":"I don't understand how the memory is managed here.  The `result`Could you explain how the raw pointer `result` is eventually deleted?","created_at":"2016-04-21T16:21:03Z","updated_at":"2016-04-21T16:21:03Z","html_url":"https://github.com/highfidelity/hifi/pull/7719#discussion_r60611902","pull_request_url":"https://api.github.com/repos/highfidelity/hifi/pulls/7719","_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/60611902"},"html":{"href":"https://github.com/highfidelity/hifi/pull/7719#discussion_r60611902"},"pull_request":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7719"}}},"pull_request":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/7719","id":67147851,"html_url":"https://github.com/highfidelity/hifi/pull/7719","diff_url":"https://github.com/highfidelity/hifi/pull/7719.diff","patch_url":"https://github.com/highfidelity/hifi/pull/7719.patch","issue_url":"https://api.github.com/repos/highfidelity/hifi/issues/7719","number":7719,"state":"open","locked":false,"title":"Add prefetching to exposed caches","user":{"login":"zzmp","id":5403956,"avatar_url":"https://avatars.githubusercontent.com/u/5403956?v=3","gravatar_id":"","url":"https://api.github.com/users/zzmp","html_url":"https://github.com/zzmp","followers_url":"https://api.github.com/users/zzmp/followers","following_url":"https://api.github.com/users/zzmp/following{/other_user}","gists_url":"https://api.github.com/users/zzmp/gists{/gist_id}","starred_url":"https://api.github.com/users/zzmp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzmp/subscriptions","organizations_url":"https://api.github.com/users/zzmp/orgs","repos_url":"https://api.github.com/users/zzmp/repos","events_url":"https://api.github.com/users/zzmp/events{/privacy}","received_events_url":"https://api.github.com/users/zzmp/received_events","type":"User","site_admin":false},"body":"- Add `prefetch` to JS `ResourceCache` interface\r\n- Hold onto resources as long as JS holds a ref\r\n- Remove `MyAvatar::prefetchAnimation` and `Rig::prefetchAnimation` (and update `away.js`)\r\n- Return a `ScriptableResource` from the `prefetch` to query resource status (loaded, failed, progress)\r\n- Add a `Script.requestGarbageCollection` method to JS","created_at":"2016-04-20T08:38:32Z","updated_at":"2016-04-21T16:21:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"90123f3ca33ffd251dd656f9cd0643902215c4bd","assignee":{"login":"hyperlogic","id":20499,"avatar_url":"https://avatars.githubusercontent.com/u/20499?v=3","gravatar_id":"","url":"https://api.github.com/users/hyperlogic","html_url":"https://github.com/hyperlogic","followers_url":"https://api.github.com/users/hyperlogic/followers","following_url":"https://api.github.com/users/hyperlogic/following{/other_user}","gists_url":"https://api.github.com/users/hyperlogic/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperlogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperlogic/subscriptions","organizations_url":"https://api.github.com/users/hyperlogic/orgs","repos_url":"https://api.github.com/users/hyperlogic/repos","events_url":"https://api.github.com/users/hyperlogic/events{/privacy}","received_events_url":"https://api.github.com/users/hyperlogic/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/highfidelity/hifi/pulls/7719/commits","review_comments_url":"https://api.github.com/repos/highfidelity/hifi/pulls/7719/comments","review_comment_url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/highfidelity/hifi/issues/7719/comments","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/713fc44ec5738789dbca9973ddc539b44ce0de82","head":{"label":"zzmp:feat/resource-prefetch","ref":"feat/resource-prefetch","sha":"713fc44ec5738789dbca9973ddc539b44ce0de82","user":{"login":"zzmp","id":5403956,"avatar_url":"https://avatars.githubusercontent.com/u/5403956?v=3","gravatar_id":"","url":"https://api.github.com/users/zzmp","html_url":"https://github.com/zzmp","followers_url":"https://api.github.com/users/zzmp/followers","following_url":"https://api.github.com/users/zzmp/following{/other_user}","gists_url":"https://api.github.com/users/zzmp/gists{/gist_id}","starred_url":"https://api.github.com/users/zzmp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzmp/subscriptions","organizations_url":"https://api.github.com/users/zzmp/orgs","repos_url":"https://api.github.com/users/zzmp/repos","events_url":"https://api.github.com/users/zzmp/events{/privacy}","received_events_url":"https://api.github.com/users/zzmp/received_events","type":"User","site_admin":false},"repo":{"id":45364529,"name":"hifi","full_name":"zzmp/hifi","owner":{"login":"zzmp","id":5403956,"avatar_url":"https://avatars.githubusercontent.com/u/5403956?v=3","gravatar_id":"","url":"https://api.github.com/users/zzmp","html_url":"https://github.com/zzmp","followers_url":"https://api.github.com/users/zzmp/followers","following_url":"https://api.github.com/users/zzmp/following{/other_user}","gists_url":"https://api.github.com/users/zzmp/gists{/gist_id}","starred_url":"https://api.github.com/users/zzmp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzmp/subscriptions","organizations_url":"https://api.github.com/users/zzmp/orgs","repos_url":"https://api.github.com/users/zzmp/repos","events_url":"https://api.github.com/users/zzmp/events{/privacy}","received_events_url":"https://api.github.com/users/zzmp/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zzmp/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":true,"url":"https://api.github.com/repos/zzmp/hifi","forks_url":"https://api.github.com/repos/zzmp/hifi/forks","keys_url":"https://api.github.com/repos/zzmp/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zzmp/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zzmp/hifi/teams","hooks_url":"https://api.github.com/repos/zzmp/hifi/hooks","issue_events_url":"https://api.github.com/repos/zzmp/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/zzmp/hifi/events","assignees_url":"https://api.github.com/repos/zzmp/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/zzmp/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/zzmp/hifi/tags","blobs_url":"https://api.github.com/repos/zzmp/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zzmp/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zzmp/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/zzmp/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zzmp/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/zzmp/hifi/languages","stargazers_url":"https://api.github.com/repos/zzmp/hifi/stargazers","contributors_url":"https://api.github.com/repos/zzmp/hifi/contributors","subscribers_url":"https://api.github.com/repos/zzmp/hifi/subscribers","subscription_url":"https://api.github.com/repos/zzmp/hifi/subscription","commits_url":"https://api.github.com/repos/zzmp/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/zzmp/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/zzmp/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/zzmp/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/zzmp/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/zzmp/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zzmp/hifi/merges","archive_url":"https://api.github.com/repos/zzmp/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zzmp/hifi/downloads","issues_url":"https://api.github.com/repos/zzmp/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/zzmp/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/zzmp/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/zzmp/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zzmp/hifi/labels{/name}","releases_url":"https://api.github.com/repos/zzmp/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/zzmp/hifi/deployments","created_at":"2015-11-02T01:02:18Z","updated_at":"2016-03-24T20:39:17Z","pushed_at":"2016-04-21T03:18:57Z","git_url":"git://github.com/zzmp/hifi.git","ssh_url":"git@github.com:zzmp/hifi.git","clone_url":"https://github.com/zzmp/hifi.git","svn_url":"https://github.com/zzmp/hifi","homepage":"","size":196474,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"highfidelity:master","ref":"master","sha":"66235acac2188b27eb146c2d51407c169c6ce413","user":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"repo":{"id":5372872,"name":"hifi","full_name":"highfidelity/hifi","owner":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/highfidelity/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":false,"url":"https://api.github.com/repos/highfidelity/hifi","forks_url":"https://api.github.com/repos/highfidelity/hifi/forks","keys_url":"https://api.github.com/repos/highfidelity/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/highfidelity/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/highfidelity/hifi/teams","hooks_url":"https://api.github.com/repos/highfidelity/hifi/hooks","issue_events_url":"https://api.github.com/repos/highfidelity/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/highfidelity/hifi/events","assignees_url":"https://api.github.com/repos/highfidelity/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/highfidelity/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/highfidelity/hifi/tags","blobs_url":"https://api.github.com/repos/highfidelity/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/highfidelity/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/highfidelity/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/highfidelity/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/highfidelity/hifi/languages","stargazers_url":"https://api.github.com/repos/highfidelity/hifi/stargazers","contributors_url":"https://api.github.com/repos/highfidelity/hifi/contributors","subscribers_url":"https://api.github.com/repos/highfidelity/hifi/subscribers","subscription_url":"https://api.github.com/repos/highfidelity/hifi/subscription","commits_url":"https://api.github.com/repos/highfidelity/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/highfidelity/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/highfidelity/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/highfidelity/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/highfidelity/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/highfidelity/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/highfidelity/hifi/merges","archive_url":"https://api.github.com/repos/highfidelity/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/highfidelity/hifi/downloads","issues_url":"https://api.github.com/repos/highfidelity/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/highfidelity/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/highfidelity/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/highfidelity/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/highfidelity/hifi/labels{/name}","releases_url":"https://api.github.com/repos/highfidelity/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/highfidelity/hifi/deployments","created_at":"2012-08-10T18:26:22Z","updated_at":"2016-04-21T08:09:47Z","pushed_at":"2016-04-21T16:19:51Z","git_url":"git://github.com/highfidelity/hifi.git","ssh_url":"git@github.com:highfidelity/hifi.git","clone_url":"https://github.com/highfidelity/hifi.git","svn_url":"https://github.com/highfidelity/hifi","homepage":"","size":242527,"stargazers_count":368,"watchers_count":368,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":217,"mirror_url":null,"open_issues_count":66,"forks":217,"open_issues":66,"watchers":368,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7719"},"html":{"href":"https://github.com/highfidelity/hifi/pull/7719"},"issue":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/7719"},"comments":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/7719/comments"},"review_comments":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7719/comments"},"review_comment":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7719/commits"},"statuses":{"href":"https://api.github.com/repos/highfidelity/hifi/statuses/713fc44ec5738789dbca9973ddc539b44ce0de82"}}}}