-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
[Bug] destroy
function for artalk to avoid memory leak in SPA
#373
Comments
Discussed in #367 (reply in thread)You have reminded me that there may indeed be a memory leak, but I haven't actually verified it. In my case, I use the Artalk/docs/.vitepress/theme/Artalk.vue Line 25 in 34e59e6
Artalk/docs/.vitepress/theme/Artalk.vue Line 43 in 34e59e6
This is really a point to ponder, and I'm not quite sure if there are potential places where it's not CGed. (Although I try to only create listeners associated with one dom of artalk rather than lots of event listeners on the window object) Anyway, repeatedly creating new is not a good choice, especially in spa, and I also prefer to abandon the previous initialisation way (and instantiate the object only once). Ensuring that it can be effectively CGed requires some finesse, which also creates difficulty in developing programs that don't leak memory. It is easy to make this mistake. Concerning the scope of the impact: in a spa page, the program's data is saved continuously, but in a static page (such as a hugo blog), the original data is lost every time the page is refreshed, so it is not affected. |
Thanks for the issue, it's really helpful! |
destroy
function for artalk to avoid memory leak
destroy
function for artalk to avoid memory leakdestroy
function for artalk to avoid memory leak in SPA
为什么不尝试去掉 id 选择器部分?移除 Artalk/ui/packages/artalk/src/layer/layer.ts Lines 151 to 156 in 3b99a58
|
因为当初设计是想多个 Artalk 实例互不干扰,一页有多个互相隔离的独立 Artalk 实例,例如两个评论框,他们不会因为公用相同的 Layer Wrap 元素而造成干扰。 但这个功能似乎并没有什么用,既增加了代码复杂度,难以维护,又为前端部署带来问题,以后想直接删掉这个特性,只允许一个页面创建一个 Artalk 实例,类似单例模式的实现。 |
v2.5.0 (2023-03-10) 新版已发布 |
Artalk needs an destroy method to remove all event listerner and callback functions to prevent memory increasing.
Also, the destroy method should remove extra dom besides cleaning the original object.
E.g.:
div.atk-layer-wrap
it inserts during initialization.The text was updated successfully, but these errors were encountered: