Memory usage is gradually increasing with javascript websockets.Why?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a web app using javascript websockets to fetch and render realtime data.The problem is once the websocket connection is established,the memory usage of my browser gradually increases in MBs.
Once I close the tab,the memory usage drops by the same amount as it increased.
I am rendering the data received through websockets to google chart as well and the data is received every 2 seconds triggering a re-render of the chart with new data.Could that be the issue?Or are websockets causing the rise in memory usage?
javascript performance
add a comment |
I have a web app using javascript websockets to fetch and render realtime data.The problem is once the websocket connection is established,the memory usage of my browser gradually increases in MBs.
Once I close the tab,the memory usage drops by the same amount as it increased.
I am rendering the data received through websockets to google chart as well and the data is received every 2 seconds triggering a re-render of the chart with new data.Could that be the issue?Or are websockets causing the rise in memory usage?
javascript performance
add a comment |
I have a web app using javascript websockets to fetch and render realtime data.The problem is once the websocket connection is established,the memory usage of my browser gradually increases in MBs.
Once I close the tab,the memory usage drops by the same amount as it increased.
I am rendering the data received through websockets to google chart as well and the data is received every 2 seconds triggering a re-render of the chart with new data.Could that be the issue?Or are websockets causing the rise in memory usage?
javascript performance
I have a web app using javascript websockets to fetch and render realtime data.The problem is once the websocket connection is established,the memory usage of my browser gradually increases in MBs.
Once I close the tab,the memory usage drops by the same amount as it increased.
I am rendering the data received through websockets to google chart as well and the data is received every 2 seconds triggering a re-render of the chart with new data.Could that be the issue?Or are websockets causing the rise in memory usage?
javascript performance
javascript performance
asked Nov 29 '18 at 5:23
midhun lcmidhun lc
14
14
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
There's no way we can have any concrete idea what is causing this problem without knowing a lot more about your app and seeing your code and probably instrumenting it as described below.
It's not a generic problem with webSockets. webSockets can be open and receiving data for years without causing memory to increase.
These problems are solved by methods like these:
- Code inspection (find a place where data is accumulated indefinitely)
- Finding articles about people having similar problems and looking at their solutions to see if they apply to you
- Instruction to take heap snapshots, comparing them with previous ones and seeing what kind of objects are accumulating and then using that knowledge to find the source of the data accumulation.
See How to Record Heap Snapshots in Chrome for a very detailed description of doing memory use debugging. There's not really anything more specific than that we can tell you based on the limit info we have on your specific case.
You could probably eliminate webSockets from the equation entirely by not connecting your webSocket and then just simulate getting data from the webSocket by running setInterval() and rerendering your chart over and over. That might at least eliminate some of your code as a suspect.
FYI, here are a couple other articles to look at:
Memory leak using google charts with ajax
Memory leak in google line charts
Quick tips for squeezing memory leaks out of Google's Javascript charts with live (continuous) data/streams
Profiling memory usage in Chrome
add a comment |
I figured out the problem.
Thanks @jFriend00 for the guidance.
I assumed the problem to be with websocket after some lazy reading of blogs/posts/articles and posted the question here after that.
I re-checked my code and found that the issue was with re-rendering charts every second.I was creating a new instance of the chart for rendering every second.I was hoping GC would do the job of clearing up the old chart but it wasn't so.
I modified my code to clear the existing chart and render the same with new data and Voila! my memory consumption is back to normal.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532365%2fmemory-usage-is-gradually-increasing-with-javascript-websockets-why%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There's no way we can have any concrete idea what is causing this problem without knowing a lot more about your app and seeing your code and probably instrumenting it as described below.
It's not a generic problem with webSockets. webSockets can be open and receiving data for years without causing memory to increase.
These problems are solved by methods like these:
- Code inspection (find a place where data is accumulated indefinitely)
- Finding articles about people having similar problems and looking at their solutions to see if they apply to you
- Instruction to take heap snapshots, comparing them with previous ones and seeing what kind of objects are accumulating and then using that knowledge to find the source of the data accumulation.
See How to Record Heap Snapshots in Chrome for a very detailed description of doing memory use debugging. There's not really anything more specific than that we can tell you based on the limit info we have on your specific case.
You could probably eliminate webSockets from the equation entirely by not connecting your webSocket and then just simulate getting data from the webSocket by running setInterval() and rerendering your chart over and over. That might at least eliminate some of your code as a suspect.
FYI, here are a couple other articles to look at:
Memory leak using google charts with ajax
Memory leak in google line charts
Quick tips for squeezing memory leaks out of Google's Javascript charts with live (continuous) data/streams
Profiling memory usage in Chrome
add a comment |
There's no way we can have any concrete idea what is causing this problem without knowing a lot more about your app and seeing your code and probably instrumenting it as described below.
It's not a generic problem with webSockets. webSockets can be open and receiving data for years without causing memory to increase.
These problems are solved by methods like these:
- Code inspection (find a place where data is accumulated indefinitely)
- Finding articles about people having similar problems and looking at their solutions to see if they apply to you
- Instruction to take heap snapshots, comparing them with previous ones and seeing what kind of objects are accumulating and then using that knowledge to find the source of the data accumulation.
See How to Record Heap Snapshots in Chrome for a very detailed description of doing memory use debugging. There's not really anything more specific than that we can tell you based on the limit info we have on your specific case.
You could probably eliminate webSockets from the equation entirely by not connecting your webSocket and then just simulate getting data from the webSocket by running setInterval() and rerendering your chart over and over. That might at least eliminate some of your code as a suspect.
FYI, here are a couple other articles to look at:
Memory leak using google charts with ajax
Memory leak in google line charts
Quick tips for squeezing memory leaks out of Google's Javascript charts with live (continuous) data/streams
Profiling memory usage in Chrome
add a comment |
There's no way we can have any concrete idea what is causing this problem without knowing a lot more about your app and seeing your code and probably instrumenting it as described below.
It's not a generic problem with webSockets. webSockets can be open and receiving data for years without causing memory to increase.
These problems are solved by methods like these:
- Code inspection (find a place where data is accumulated indefinitely)
- Finding articles about people having similar problems and looking at their solutions to see if they apply to you
- Instruction to take heap snapshots, comparing them with previous ones and seeing what kind of objects are accumulating and then using that knowledge to find the source of the data accumulation.
See How to Record Heap Snapshots in Chrome for a very detailed description of doing memory use debugging. There's not really anything more specific than that we can tell you based on the limit info we have on your specific case.
You could probably eliminate webSockets from the equation entirely by not connecting your webSocket and then just simulate getting data from the webSocket by running setInterval() and rerendering your chart over and over. That might at least eliminate some of your code as a suspect.
FYI, here are a couple other articles to look at:
Memory leak using google charts with ajax
Memory leak in google line charts
Quick tips for squeezing memory leaks out of Google's Javascript charts with live (continuous) data/streams
Profiling memory usage in Chrome
There's no way we can have any concrete idea what is causing this problem without knowing a lot more about your app and seeing your code and probably instrumenting it as described below.
It's not a generic problem with webSockets. webSockets can be open and receiving data for years without causing memory to increase.
These problems are solved by methods like these:
- Code inspection (find a place where data is accumulated indefinitely)
- Finding articles about people having similar problems and looking at their solutions to see if they apply to you
- Instruction to take heap snapshots, comparing them with previous ones and seeing what kind of objects are accumulating and then using that knowledge to find the source of the data accumulation.
See How to Record Heap Snapshots in Chrome for a very detailed description of doing memory use debugging. There's not really anything more specific than that we can tell you based on the limit info we have on your specific case.
You could probably eliminate webSockets from the equation entirely by not connecting your webSocket and then just simulate getting data from the webSocket by running setInterval() and rerendering your chart over and over. That might at least eliminate some of your code as a suspect.
FYI, here are a couple other articles to look at:
Memory leak using google charts with ajax
Memory leak in google line charts
Quick tips for squeezing memory leaks out of Google's Javascript charts with live (continuous) data/streams
Profiling memory usage in Chrome
edited Nov 29 '18 at 5:52
answered Nov 29 '18 at 5:46
jfriend00jfriend00
442k55581624
442k55581624
add a comment |
add a comment |
I figured out the problem.
Thanks @jFriend00 for the guidance.
I assumed the problem to be with websocket after some lazy reading of blogs/posts/articles and posted the question here after that.
I re-checked my code and found that the issue was with re-rendering charts every second.I was creating a new instance of the chart for rendering every second.I was hoping GC would do the job of clearing up the old chart but it wasn't so.
I modified my code to clear the existing chart and render the same with new data and Voila! my memory consumption is back to normal.
add a comment |
I figured out the problem.
Thanks @jFriend00 for the guidance.
I assumed the problem to be with websocket after some lazy reading of blogs/posts/articles and posted the question here after that.
I re-checked my code and found that the issue was with re-rendering charts every second.I was creating a new instance of the chart for rendering every second.I was hoping GC would do the job of clearing up the old chart but it wasn't so.
I modified my code to clear the existing chart and render the same with new data and Voila! my memory consumption is back to normal.
add a comment |
I figured out the problem.
Thanks @jFriend00 for the guidance.
I assumed the problem to be with websocket after some lazy reading of blogs/posts/articles and posted the question here after that.
I re-checked my code and found that the issue was with re-rendering charts every second.I was creating a new instance of the chart for rendering every second.I was hoping GC would do the job of clearing up the old chart but it wasn't so.
I modified my code to clear the existing chart and render the same with new data and Voila! my memory consumption is back to normal.
I figured out the problem.
Thanks @jFriend00 for the guidance.
I assumed the problem to be with websocket after some lazy reading of blogs/posts/articles and posted the question here after that.
I re-checked my code and found that the issue was with re-rendering charts every second.I was creating a new instance of the chart for rendering every second.I was hoping GC would do the job of clearing up the old chart but it wasn't so.
I modified my code to clear the existing chart and render the same with new data and Voila! my memory consumption is back to normal.
answered Nov 29 '18 at 8:23
midhun lcmidhun lc
14
14
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532365%2fmemory-usage-is-gradually-increasing-with-javascript-websockets-why%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown