Hi I am trying to import a huge data. its around 8GB having more then 53k files. What i want is to import one file at a time, done with its usage and then delete/remove or garbage collect the cache.
I know when we use delete
keyword it only delete the reference of obj instance. Delete or making variable value to null
or undefined
doesn't work.
Here is my code.
fs.readdir(dirname, (err, filenames) => {
if (err) {
onError(err);
return;
}
_.forEach(filenames, (file) => {
if (!!~file.indexOf('.json')) {
this.synchronize(() => {
let currentFile = require(`${dirname}${file}`);
return new Promise((resolve, reject) => {
setTimeout(() => {
//assume am done working with the data imported in variable currentFile here. now i want to delete it.
resolve('Done');
}, 1)
})
})
}
});
});
I tried every possible way to make the cache empty but not succeeded.
Is there any way to clear the currentFile
after am done working on it?
Or may be how to tweak my code to achieve the functionality that it will work for any number of files in the folder.
any help will be appreciated