WebPlatformForEmbedded / WPEWebKit

WPE WebKit port (downstream)
211 stars 135 forks source link

Memory consumption/leak with img out of viewport and lazy loading #1234

Closed pgorszkowski-igalia closed 9 months ago

pgorszkowski-igalia commented 9 months ago

https://bugs.webkit.org/show_bug.cgi?id=263521

Reviewed by Chris Dumez.

This change fixes the problem with dangling of dynamically created (in JS) HTMLImageElement when it is detached from the document before loading the resource starts. It happened when img element was created (dynamically) with lazy loading and the element was outside the viewport (the loading of resource is deferred until the img element becomes visible). If the element was removed from document it becomes dangling element and will never be deleted by GC.

To avoid leaking of the dynamically created element, the pending activity of the element should check has the load of the resource actually started. Similar check is done in case of static HTMLImageElement in ImageLoader::updatedHasPendingEvent.

Moved implementation to cpp file.

Canonical link: https://commits.webkit.org/270745@main