diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 4a80628da4..d1dabd5693 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -123,13 +123,13 @@ ScriptableResource::ScriptableResource(const QUrl& url) : QObject(nullptr), _url(url) {} +void ScriptableResource::release() { + disconnectHelper(); + _resource.reset(); +} + void ScriptableResource::finished(bool success) { - if (_progressConnection) { - disconnect(_progressConnection); - } - if (_finishedConnection) { - disconnect(_finishedConnection); - } + disconnectHelper(); _isLoaded = true; _isFailed = !success; @@ -140,6 +140,15 @@ void ScriptableResource::finished(bool success) { emit loadedChanged(_isLoaded); } +void ScriptableResource::disconnectHelper() { + if (_progressConnection) { + disconnect(_progressConnection); + } + if (_finishedConnection) { + disconnect(_finishedConnection); + } +} + ScriptableResource* ResourceCache::prefetch(const QUrl& url, void* extra) { auto result = new ScriptableResource(url); diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 35a0710aa6..997c9be37d 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -89,6 +89,8 @@ public: ScriptableResource(const QUrl& url); virtual ~ScriptableResource() = default; + Q_INVOKABLE void release(); + const QUrl& getUrl() const { return _url; } bool isLoaded() const { return _isLoaded; } bool isFailed() const { return _isFailed; } @@ -102,6 +104,8 @@ private slots: void finished(bool success); private: + void disconnectHelper(); + friend class ResourceCache; // Holds a ref to the resource to keep it in scope