question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory Issue In Buffers

See original GitHub issue

Hello,

I have a large array that needs to be sent over a socket connection from a server (Node Js) to a Client (Holo Js / Hololens) every second or so. Sending it as a normal array is kind of slow so i resorted to converting the list to a buffer.

var buffer = new Float64Array(list).buffer
var data = {
	buffer : buffer
}
client.emit('sendData', data);

However, I realized that the app would crash and start throwing an out of memory exception after a while. After looking into it more i realized that the memory displayed on the diagnostic tools view in visual studio keeps increasing every time a new buffer is being received. This does not happen when receiving a normal array.

I attached a sample node js server NodeJs - Socket Server.zip

And here is a small script to run on HoloJs to replicate the problem.

var url = "http://{ip}:{port}/";
var socket = io(url, { transports: ['websocket'] });

socket.on('connect', function () {
    console.log('connected');
    socket.emit('requestData');
});

socket.on('sendData', function (data) {
    socket.emit('requestData');
});

Another thing i tried that caused the same behavior is this:


setInterval(function () {
    var test = [];
    for (var i = 0; i < 100000; i++) {
        test.push(i);
    }
    var data = {
        test: test
    };
   // console.log(data);
}, 100);

When i comment out the console.log no issues happen but adding it would cause the memory to keep increasing until eventually the app crashes due to an out of memory exception.

Regards, Omar.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Almost-Donecommented, Jan 31, 2018

PS: Thank you for investigating and reporting this issue. Please let me know if you see memory leaks with the fixes above.

0reactions
omaralcheikhcommented, Feb 1, 2018

Thank you Cristi, its working great now and memory is stable. Please note that i get this error sometimes:

Exception thrown at 0x77442552 in ThreeJSApp-Vs2017.exe: Microsoft C++ exception: Js::RejitException at memory location 0x087FF117.

but it seems that it doesn’t affect anything and the script just keeps running normally.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting OutOfMemoryError: Direct buffer memory
Symptoms of the Direct Buffer Memory issue ... As we said, the Direct Buffers are allocated to native memory space outside of the...
Read more >
Buffer Memory - an overview | ScienceDirect Topics
A write buffer is a very small, fast FIFO memory buffer that temporarily holds data that the processor would normally write to main...
Read more >
Memory Buffer Errors | Martello Security
Any condition where the attacker has the ability to write an arbitrary value to an arbitrary location, often as the result of a...
Read more >
Memory leak when reading into buffer - Stack Overflow
When running valgrind, there appears to be a memory leak, but I'm not sure what the issue is. I free'd the buffer's memory...
Read more >
Buffer.from(str) memory leak #38300 - nodejs/node - GitHub
Created buffers should be garbage collected, and memory usage shouldn't increase too much during execution. What do you see instead? Memory ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found