Viewers icon indicating copy to clipboard operation
Viewers copied to clipboard

JavaScript heap out of memory

Open trung1704ptit opened this issue 6 years ago • 9 comments

I am using Ubuntu with Node v10.15.2, yarn v1.9.1 I took the latest version of repository, When I try to edit something in dev mode, sowetime project will be crashed with error: Heap out of memory.

@ohif/viewer: ℹ 「wdm」: Compiled with warnings. @ohif/viewer: ℹ 「wdm」: Compiling... @ohif/viewer: <--- Last few GCs ---> @ohif/viewer: [18954:0x1a1d040] 635442 ms: Mark-sweep 1357.6 (1390.2) -> 1356.1 (1377.9) MB, 93.8 / 0.0 ms (average mu = 0.951, current mu = 0.170) last resort GC in old space requested @ohif/viewer: [18954:0x1a1d040] 635560 ms: Mark-sweep 1356.1 (1377.9) -> 1356.1 (1377.9) MB, 117.6 / 0.0 ms (average mu = 0.898, current mu = 0.000) last resort GC in old space requested @ohif/viewer: <--- JS stacktrace ---> @ohif/viewer: ==== JS stack trace ========================================= @ohif/viewer: 0: ExitFrame [pc: 0x110d107d452b] @ohif/viewer: Security context: 0x038a82daede9 <JSObject> @ohif/viewer: 1: fromString(aka fromString) [0x5758e6f0861] [buffer.js:339] [bytecode=0xdc29ae70f21 offset=53](this=0x1065f74025d9 <undefined>,string=0x3db73e9780c9 <Very long string[46239588]>,encoding=0x038a82df1891 <String[4]: utf8>) @ohif/viewer: 2: from [0x24d9fec1cd9] [buffer.js:200] [bytecode=0xdc29ae70aa1 offset=11](this=0x339ce1db0fc9 <JSFunction Buffer (sfi = 0x24d9fe... @ohif/viewer: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory @ohif/viewer: 1: 0x7f3180dee568 node::Abort() [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 2: 0x7f3180dee5b1 [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 3: 0x7f3180fafd22 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 4: 0x7f3180faff78 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 5: 0x7f31813315f2 [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 6: 0x7f3181345197 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 7: 0x7f3181313749 v8::internal::Factory::AllocateRawWithImmortalMap(int, v8::internal::PretenureFlag, v8::internal::Map*, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 8: 0x7f318131ab31 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 9: 0x7f3181445285 v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 10: 0x7f3180fb99e0 v8::String::Utf8Length() const [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 11: 0x7f3180e07cb1 [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 12: 0x7f318102f62c [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 13: 0x7f3181030c06 [/lib/x86_64-linux-gnu/libnode.so.64] @ohif/viewer: 14: 0x110d107d452b @ohif/viewer: error Command failed with exit code 1. @ohif/viewer: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. @ohif/viewer: error Command failed with exit code 1. @ohif/viewer: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. lerna ERR! yarn run dev:viewer exited 1 in '@ohif/viewer' error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Anyone can solve it, please let me know, Thanks

trung1704ptit avatar Jan 04 '20 03:01 trung1704ptit

Same thing has been happening to me these days. I'm on Mac OSX.

dsimic avatar Jan 05 '20 06:01 dsimic

@dsimic I need to fix limit memory in node: export NODE_OPTIONS="--max_old_space_size=8192"

trung1704ptit avatar Jan 06 '20 07:01 trung1704ptit

This has been on our list to address for a while. I've been hoping several code splitting and bundle reduction steps we're taking will alleviate the problem. If you have more concrete advice, I am all ears.

dannyrb avatar Jan 06 '20 13:01 dannyrb

@dannyrb I think this proplem can be solve by add "export NODE_OPTIONS="--max_old_space_size=8192"

I have an other question that: how can I get the gray scale array of image (DICOM image after converted).

I just see the result after application render the canvas but we need to use the gray scale before we show the result. Our product needs gray scale array to process image. Please show me how I can get the gray scale array of image from DICOM.

Thank you so much

trung1704ptit avatar Jan 08 '20 03:01 trung1704ptit

I'm not entirely sure I follow. Do you want the raw pixel data for the image? Or are you looking for the generated LUT that condenses the range?

A Cornerstone Image object has a getPixelData method that returns the underlying pixel data. (An array of integers for grayscale and an array of RGBA for color)

See: https://docs.cornerstonejs.org/api.html

dannyrb avatar Jan 08 '20 03:01 dannyrb

@dannyrb thanks for your response,

I tried to read the document, I knew about this method, But how can I access the method getPixelData.I don't know where I can access it in your code. The step are:

  1. Open DICOM file
  2. Access the getPixelData to get integers for grayscale.
  3. Processing.

So we need to getPixelData after we open DICOM. Do you have any ideal? Please help me.

trung1704ptit avatar Jan 08 '20 04:01 trung1704ptit

There are a lot of ways to accomplish this. I'm still not sure I understand what user experience you're trying to achieve. I'm also not sure I understand why you're choosing to do this on the client instead of on the server.

If you can provide more information, I can better assist you.

dannyrb avatar Jan 08 '20 12:01 dannyrb

@dannyrb , We use this viewer for client side, the User (doctors) can submit the DICOM files to server. We are using AI in our server to detect disease.

I got the gray scale in code, but I think it too large. One gray scale data is arround 2.7MB. So we decided upload dicom file to server instead of using grayscale data.

Forgot that, I am trying to handle event Stack Scroll, but I don't know how can I access the callback of this event or how can I trigger this event. I mean, after upload the dicom files to server, I will have the response from AI for this patient, when I scroll mouse on DICOM image view, I need to trigger this event to show the result of each dicom file.

Please help me. Thanks

trung1704ptit avatar Jan 10 '20 08:01 trung1704ptit

Cornerstone's new image event: https://github.com/cornerstonejs/cornerstone/blob/master/src/events.js#L2

We've strayed quite a bit from the original issue, which you appear to have resolved. I'm going to close this. Feel free to create new issues if you have additional questions.

dannyrb avatar Jan 10 '20 14:01 dannyrb