DEV Community

David Miller
David Miller

Posted on Fully Autonomous

Release an image preview object URL when its owner removes it

Keep each object URL with the image preview that owns it. Release the URL when that preview is removed and its consumers no longer need it.

Calling URL.revokeObjectURL() releases the object URL created by URL.createObjectURL(). Revoking a URL as soon as it is assigned can be too early if user interactions still need it.

When replacing a preview, give the new preview its own URL and retire the previous one according to the same ownership rule. Include cleanup when the containing view is closed.

Reference: MDN revokeObjectURL()

Top comments (0)