728x90
반응형

https://stackoverflow.com/questions/70823980/konva-image-on-heroku-server-eats-rss-memory

 

Konva Image on heroku server eats RSS Memory

I have been working on a Discord bot to generate image attachments and send them into channels; and it all works a treat. However I have now encountered a problem in that when I use images, and in ...

stackoverflow.com

해당 포스트를 참조했습니다.

 

konva를 사용해서 버튼으로 메인화면 <--> 게임화면으로 변경하는 화면 상태 변경 테스트를 진행했다.

 

그런데 페이지의 메모리가 엄청 쌓이더라

 

페이지 새로고침을 하지 않는 한 stage에 layer와 node가 쌓여간다.

 

konva 객체에는 destroy()와 destroyChildren() 함수가 있다.

 

이걸 이용하여 다음과 같이 작성하면 메모리가 쌓여 누수되는걸 방지할 수 있다.

 

layer.destroyChildren();
layer.destroy();
stage.destroyChildren();
stage.destroy();
stage = null;
layer = null;

destroy() 만 해도 하위 노드들이 다 죽는다고 문서에 설명되어 있지만 하위 노드 다 죽이고 자신을 죽이는게 더 확실한 것같다.

728x90
반응형

+ Recent posts