-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This library is a memory leak #264
Comments
Also, |
so how can I solve this problem? could you please tell me How can I modify the code to fix it? |
Fork the repository
Fix code
Pull Request
…On Tue, Mar 28, 2023 at 8:45 AM quanxufeng ***@***.***> wrote:
When calling SMA or other indicators relying on LinkedList the LinkedList items never get garbage collected. This is due to the structure of LinkedList that always contains reference to the next and previous element.
In NodeJS you must remove reference to the unused items for them to be disposed by GC.
so how can I solve this problem? could you please tell me How can I modify the code to fix it?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
To solve this problem, you can create a custom LinkedList class that has built-in garbage collection support. This class will automatically remove references to unused items, allowing them to be properly disposed of by the garbage collector. Here's an example implementation:
Now, you can use this custom LinkedList class to store your SMA or other indicator values. Whenever you no longer need a value, call the remove or removeFirst method, depending on your use case, to remove it from the list. This will ensure that the garbage collector disposes of the unused items properly. For example:
By managing your LinkedList items this way, you can ensure that unused items are correctly garbage collected, preventing memory leaks and improving your application's performance. |
Hi, episage, thanks for your reply, is there a method or a way that I can directly remove values or empty the list? can I access to the reference of the values list in this library? |
Yes, you can add a method to the custom GCLinkedList class to clear the list and remove all references to the values. Here's the updated class with the new clear method:
This clear method iterates through the list, removing references to the prev and next nodes, effectively clearing the list. After calling this method, the garbage collector will be able to dispose of the unused items properly. To use the clear method, simply call it on your GCLinkedList instance:
Regarding direct access to the values list, the custom GCLinkedList class does not store the values in a separate list or array, as it uses a linked list structure with nodes referencing each other. However, you can create a method to retrieve all values as an array:
Now you can access the list values as an array:
This will output an array containing the values of the nodes in the list. |
When calling
SMA
or other indicators relying onLinkedList
theLinkedList
items never get garbage collected. This is due to the structure ofLinkedList
that always contains reference to the next and previous element.In NodeJS you must remove reference to the unused items for them to be disposed by GC.
The text was updated successfully, but these errors were encountered: