Title: [91384] trunk/Source/WebCore
- Revision
- 91384
- Author
- [email protected]
- Date
- 2011-07-20 11:45:47 -0700 (Wed, 20 Jul 2011)
Log Message
Patch by Scott Graham <[email protected]> on 2011-07-20
Reviewed by Antti Koivisto.
REGRESSION (r39725?): Resources removed from document can not be freed
until the document is deleted
https://bugs.webkit.org/show_bug.cgi?id=61006
Upon completing a load start a Timer to iterate through
CachedResourceLoader's m_documentResources map to check for any items
that have only one reference (thus being the reference in the map
itself). The map should really be weak, but because the
CachedResourceHandle achieves bookkeeping work in addition to
reference counting, this is a simpler and more localized way to free
the used memory while maintaining the other behaviour (when
CachedResource is used as proxy).
No new layout tests, but with this patch the testcase at
https://bugs.webkit.org/attachment.cgi?id=93850 should no longer
consume 400MB of ram on load.
* loader/cache/CachedResource.h:
(WebCore::CachedResource::getHandleCount):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::loadDone):
(WebCore::CachedResourceLoader::garbageCollectDocumentResources):
* loader/cache/CachedResourceLoader.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (91383 => 91384)
--- trunk/Source/WebCore/ChangeLog 2011-07-20 18:43:43 UTC (rev 91383)
+++ trunk/Source/WebCore/ChangeLog 2011-07-20 18:45:47 UTC (rev 91384)
@@ -1,3 +1,31 @@
+2011-07-20 Scott Graham <[email protected]>
+
+ Reviewed by Antti Koivisto.
+
+ REGRESSION (r39725?): Resources removed from document can not be freed
+ until the document is deleted
+ https://bugs.webkit.org/show_bug.cgi?id=61006
+
+ Upon completing a load start a Timer to iterate through
+ CachedResourceLoader's m_documentResources map to check for any items
+ that have only one reference (thus being the reference in the map
+ itself). The map should really be weak, but because the
+ CachedResourceHandle achieves bookkeeping work in addition to
+ reference counting, this is a simpler and more localized way to free
+ the used memory while maintaining the other behaviour (when
+ CachedResource is used as proxy).
+
+ No new layout tests, but with this patch the testcase at
+ https://bugs.webkit.org/attachment.cgi?id=93850 should no longer
+ consume 400MB of ram on load.
+
+ * loader/cache/CachedResource.h:
+ (WebCore::CachedResource::getHandleCount):
+ * loader/cache/CachedResourceLoader.cpp:
+ (WebCore::CachedResourceLoader::loadDone):
+ (WebCore::CachedResourceLoader::garbageCollectDocumentResources):
+ * loader/cache/CachedResourceLoader.h:
+
2011-07-20 James Robinson <[email protected]>
Revert worker and WebKit2 runloops to use currentTime() for scheduling instead of the monotonic clock
Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (91383 => 91384)
--- trunk/Source/WebCore/loader/cache/CachedResource.h 2011-07-20 18:43:43 UTC (rev 91383)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h 2011-07-20 18:45:47 UTC (rev 91384)
@@ -182,6 +182,7 @@
CachedMetadata* cachedMetadata(unsigned dataTypeID) const;
bool canDelete() const { return !hasClients() && !m_request && !m_preloadCount && !m_handleCount && !m_resourceToRevalidate && !m_proxyResource; }
+ bool hasOneHandle() const { return m_handleCount == 1; }
bool isExpired() const;
Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (91383 => 91384)
--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2011-07-20 18:43:43 UTC (rev 91383)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2011-07-20 18:45:47 UTC (rev 91384)
@@ -86,6 +86,7 @@
CachedResourceLoader::CachedResourceLoader(Document* document)
: m_document(document)
, m_requestCount(0)
+ , m_garbageCollectDocumentResourcesTimer(this, &CachedResourceLoader::garbageCollectDocumentResourcesTimerFired)
, m_autoLoadImages(true)
, m_loadFinishing(false)
, m_allowStaleResources(false)
@@ -561,8 +562,30 @@
if (frame())
frame()->loader()->loadDone();
performPostLoadActions();
+
+ if (!m_garbageCollectDocumentResourcesTimer.isActive())
+ m_garbageCollectDocumentResourcesTimer.startOneShot(0);
}
+// Garbage collecting m_documentResources is a workaround for the
+// CachedResourceHandles on the RHS being strong references. Ideally this
+// would be a weak map, however CachedResourceHandles perform additional
+// bookkeeping on CachedResources, so instead pseudo-GC them -- when the
+// reference count reaches 1, m_documentResources is the only reference, so
+// remove it from the map.
+void CachedResourceLoader::garbageCollectDocumentResourcesTimerFired(Timer<CachedResourceLoader>* timer)
+{
+ Vector<String, 10> toDelete;
+
+ for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != m_documentResources.end(); ++it) {
+ if (it->second->hasOneHandle())
+ toDelete.append(it->first);
+ }
+
+ for (Vector<String, 10>::const_iterator idel = toDelete.begin(); idel != toDelete.end(); ++idel)
+ m_documentResources.remove(*idel);
+}
+
void CachedResourceLoader::performPostLoadActions()
{
checkForPendingPreloads();
Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.h (91383 => 91384)
--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.h 2011-07-20 18:43:43 UTC (rev 91383)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.h 2011-07-20 18:45:47 UTC (rev 91384)
@@ -30,6 +30,7 @@
#include "CachedResourceHandle.h"
#include "CachePolicy.h"
#include "ResourceLoadPriority.h"
+#include "Timer.h"
#include <wtf/Deque.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
@@ -117,6 +118,7 @@
void notifyLoadedFromMemoryCache(CachedResource*);
bool canRequest(CachedResource::Type, const KURL&, bool forPreload = false);
+ void garbageCollectDocumentResourcesTimerFired(Timer<CachedResourceLoader>*);
void performPostLoadActions();
HashSet<String> m_validatedURLs;
@@ -132,6 +134,8 @@
String m_charset;
};
Deque<PendingPreload> m_pendingPreloads;
+
+ Timer<CachedResourceLoader> m_garbageCollectDocumentResourcesTimer;
//29 bits left
bool m_autoLoadImages : 1;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes