Question regarding memory management in a JavaScript program.
In my code, I have a global array called g_objArr
, which is used to store customer profile details. This array contains objects with various customer information fields.
The issue arises when the g_objArr
gets reset and reloaded with new data each time a different customer profile is selected using the function loadCustomerDetails()
. This constant reloading of large arrays is causing excessive memory usage in my application.
Initially, I tried clearing the array by setting g_objArr.length = 0
to destroy references to previous objects. However, my teammate suggested that instead of manually clearing the array, we should identify and remove any lingering references to objects within it so that the garbage collector can handle it automatically.
Considering the widespread use of g_objArr
throughout the codebase, pinpointing these dangling references may be time-consuming. Upon initial examination, I couldn't find any obvious culprits apart from loop iterations.
So, the question remains: Should we rely on the garbage collector to clean up unused object references in the global array, or do we need to explicitly clear it every time? Is there perhaps a memory analysis tool in vscode that could help us address this issue more efficiently?
Thank you for your insights!
Additional note: The application is locally hosted on vscode, not on a web server.