javascript - innerHTML img Memory Leak
问题描述
The tcp server continues to forward the new image path.
The client continues to update the image through the path it receives.
I think .innerHTML = "<img
makes memory leak
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
const socket = io();
socket.on('data', (msg)=>{
document.getElementById('IMG').innerHTML = "<img src="+msg.imagePath + ">";
});
</script>
This is my second plan.
How can I keep changing the image without any memory leak?
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
const socket = io();
socket.on('data', (msg)=>{
(function(){
document.getElementById('IMG').innerHTML = "<img src="+msg.imagePath + ">";
}());
});
</script>
解决方案
您只能更改src
:
document.querySelector('#IMG').setAttribute('src', msg.imagePath);
推荐阅读
- c# - 如何并行执行 Web 请求?
- node.js - NodeJS,Mongoose:必填字段验证
- julia - 非线性求解器总是产生零残差
- reactjs - 在 TypeScript 项目中处理自己编写的类型定义
- windows - windows buildpacks 如何使用 windows 功能/服务?
- javascript - 如何在点击时选择“这个”?
- python - 在 python 中使用 np.ndarray 交叉遗传算法
- azure-active-directory - 应用角色未在访问令牌中传递
- robotframework - 如何使用机器人框架自动化谷歌地图 API
- java - 包的开发人员警告,无法在频道“null”上发布通知有关详细信息,请参阅日志