Skip to content

当图片加载失败时globalImageCache可导致内存泄漏 #1072

Description

@karl-barkmann

我在做我们产品的内存快照分析时发现了这个问题:
image
通过快照发现 imageOnLoad 已触发,但 pending 队列仍保留很多 pendingWrap 对象,导致内存泄漏。

#339 与这个issue相似,createOrUpdateImage 函数在获取已存在 image时,是通过判断图片元素是否有尺寸来决定要不要添加到 pending 队列。

!isImageReady(image) && cachedImgObj.pending.push(pendingWrap);

return image && image.width && image.height;

但如果图片已加载失败(不会再触发imageOnLoad回调),图片的width和height都会为0,则后续的调用将导致这个图片的pending队列一直增加,进而产生内存泄漏。

或许可以添加一个图片是否已完成加载(无论成功与否)的标记,通过该标记判断是否需要添加到pending队列?

### Tasks
- [ ] https://github.com/ecomfe/zrender/pull/1073

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions