fixed memory leak when display multframe, share for everyone,want to help others
Opened this issue · 0 comments
when I use cornerstone to display multframe and scroll to change, The memory increase very fast .
I found the reason is possMessage to worker, transfer param do not add and the type of pixelData param is Unit8, not arraybuff.
I change like this:
cornerstoneWADOImageLoader.js
processDecodeTask method 831 line
function processDecodeTask(imageFrame, transferSyntax, pixelData, options) {
let passs_pixelData = new Uint8Array(pixelData.slice(0)); //copy pixelData, pass worker not clear data ,new .. prevent .buffer error
var priority = options.priority || undefined;
// var transferList = options.transferPixelData ? [passs_pixelData.buffer] : undefined;
var transferList = [passs_pixelData.buffer]; //worker transfer
var loaderOptions = (0, _options.getOptions)();
var strict = loaderOptions.strict,
decodeConfig = loaderOptions.decodeConfig,
useWebWorkers = loaderOptions.useWebWorkers;
if (useWebWorkers === false) {
if (codecsInitialized === false) {
(0, _decodeJPEG.initializeJPEG2000)(decodeConfig);
(0, _decodeJPEGLS.initializeJPEGLS)(decodeConfig);
codecsInitialized = true;
}
return new Promise(function (resolve, reject) {
try {
var decodeArguments = [imageFrame, transferSyntax, passs_pixelData, decodeConfig, options];
var decodedImageFrame = _decodeImageFrame2.default.apply(undefined, decodeArguments);
(0, _calculateMinMax2.default)(decodedImageFrame, strict);
resolve(decodedImageFrame);
} catch (error) {
reject(error);
}
});
}
return _webWorkerManager2.default.addTask('decodeTask', {
imageFrame: imageFrame,
transferSyntax: transferSyntax,
pixelData: passs_pixelData.buffer, //pass buffer,make transfer effect
options: options
}, priority, transferList).promise;
}