Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task
karl-barkmann opened this issue Apr 7, 2024 · 1 comment
Open
1 task

Comments

@karl-barkmann
Copy link

karl-barkmann commented Apr 7, 2024

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

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

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

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

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

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

Tasks

@plainheart
Copy link
Collaborator

为了能够更好地确认问题,能麻烦提供一个例子方便复现吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants