-
Notifications
You must be signed in to change notification settings - Fork 79
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
kb.release is too destructive #48
Comments
Understood. Knockback flags ViewModels so they are deleted twice, but if you are sharing something between two ViewModels that have different life cycles, what you describe will happen. I haven't encountered this situation myself, but white or black listing will help assuming there are no other work arounds on the client side. If this is really a need, I'd rather blacklist than white list as people customize ViewModels, they shouldn't have to list all observables they add. Can you make a case for white listing over black listing (pseudo code to describe the benefit)? Either way, what sort of API would you like? Cheers... |
Hi, I don't completely understand what needs to be disposed inorder to avoid memory leakage but I assume it's related to event binding on the models that are observerd. So my proposal is:
|
Hi Idan, Thank you for working through this with me! Deleting your complex JS structure should be avoidable, but we need to IZ> I don't completely understand what needs to be disposed inorder to KM> What needs to be disposed are the Knockout Observables. A ko.computed The tricky part comes in where you have a hierarchy of ViewModels where one So the combination between the two are causing your problem since Knockback I think your proposal is a white list proposal as you originally suggested So we could reverse your proposed algorithm to be "mark as not a ViewModel"
The other option could be to try to not clear arrays unless something in Given this latest explanation, does anything stick out to you as the best Cheers, Kevin On Mon, Oct 29, 2012 at 1:35 AM, Idan Zalzberg notifications@github.comwrote:
|
Thanks for the reply, Still, I think I am missing something here, why should the array be erased? I understand they need to traversed and every observer should be cleared from subscriptions and clear itself from the models, But how does clearing the actual arrays help here? |
You raise good points - I'm very happy to finally be challenged on these decisions... When I was writing that code, I just took a strict and exhaustive view of clearing the ViewModels to ensure any potential cycles were broken, but it sounds like I probably went too far assuming ViewModels mainly aggregated observables and other ViewModels! Let's say that I just cleared the subscriptions and unbound any Backbone events, and still traversed the full object hierarchy, but did not remove elements from arrays and did not clear properties. Would that handle most cycle cases for the JS garbage collector? Or would I still clear properties on objects and arrays elements if they were observables or ViewModels. Would either of these options solve your problem or just push it to a different place? Any what about the white listing and black listing? Do you agree that there is stronger case for black listing and would it still be necessary? I'm happy to implement the best and most expected solution, I just need to know what it is. |
I am not an expert on the JS GC but I think it works using a root tree. Since knockback binds to the models on creation, I expect it to unbind when I release, with the same magical recursion I get when I bind. |
Understood. I'll take these discussions, will prepare a less destructive version of release in the next couple of days and when you can verify that it works for you, I'll release it. Thanks for all your help on this! |
Thank you. |
Yeah no worries. I'll still do this, but if it isn't as urgent then that's totally better for me! |
Reduced destructiveness of kb.release in 0.17.1 |
Using kb.release seems to be a necessity for preventing memory leakage when creating view models.
However it seems too destructive to me. Since I am using custom ViewModel classes that extend kb.ViewModel I encounter many situations where I am loosing shared objects when releasing a viewmodel.
For example kb.release([1,2]), actually empties the array. if the array object is shared between viewmodels, this causes problems.
I would suggest instead of black listing the Backbone Models from the destruction list, why not white list what really needs to be destroyed or disconnected.
The text was updated successfully, but these errors were encountered: