-
Notifications
You must be signed in to change notification settings - Fork 488
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
DTInstance.getList() possible memory leak #284
Comments
Related to issue #282. |
Yup, I did not think about how to clear the list yet. Still thinking... |
I'm curious, what is the purpose of having the historical list of directive objects? I would think having only the current items would be enough. |
It's because I'm registring the instances one by one. It's not possible to know in advance how many datatables are instanciated. Maybe a solution is to check, each time a datatables is registred, if in the list each instance is still in the DOM or not. |
I added a timeout (1s) after which the instances that are not present in the page are removed. |
Has anyone ever said they need the whole list of instances currently on the page? I don't think having this list is necessary. A user can keep track of their needs based on the options or data, rather than the actual DataTables objects. I'd imagine the majority of use cases for DTInstances.getList() are to get the corresponding DataTables instance, in which case there has to be a better way to give the user that particular instance instead of a list of all instances from which to pick it. This is really a shortcoming in the DataTables implementation. They should be passing the instance to all callbacks. In my project's case for example, I use a rowCallback to expand and collapse a child row and I need the DataTables instance in order to do so. DT doesn't give it to me, so I have to get it from you using DTInstances.getList()[someIndex]. I shouldn't have to do this. The DT instance should be given to me as a param of the callback. I think if DataTables would pass the instance to all their callbacks, your DTInstances.getList() and DTInstances.getLast() would not be needed anymore. As an interim solution, you could take one of these approaches:
|
Searching through the code, I don't see any calls to getLast() or getList(), so you don't need the list of instances for internal use, right? |
It's not used internally. Its purpose is only for post-render operations like your example or reloading/rerender the datatables. Interesting ideas 👍 I'll see what I can change. |
Both my earlier ideas are rather roundabout. Here's a more direct approach: Just like you have the dtOptions and dtColumns attributes in the element tag, you should let the user specify a dtInstanceCallback attribute through which the user will specify the name of a callback. You'd call that function and pass it the DT instance every time it changes. The user can easily take it from there. Your DTInstances would not be needed anymore at that point. |
Why didn't I think about this simple solution 😅 |
How can i get current DTInstance if not set in html template? |
The docs say:
"A DataTable directive instance is created each time a DataTable is rendered. You can fetch it by calling ... DTInstances.getList() to fetch the entire list of instances."
I did notice the same, where as I render the table over and over, the list returned by getLast() grows bigger and bigger.
Isn't this, then, a memory leak?
If this behavior is going to stay, how can I make sure previous instances get removed?
The text was updated successfully, but these errors were encountered: