Skip to content
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

Avoiding stackoverflow when dropping large List #46

Closed
lulitao1997 opened this issue Jul 2, 2019 · 3 comments
Closed

Avoiding stackoverflow when dropping large List #46

lulitao1997 opened this issue Jul 2, 2019 · 3 comments

Comments

@lulitao1997
Copy link
Contributor

lulitao1997 commented Jul 2, 2019

As #41 suggests, when dropping a large List, rust recursively calls Arc's drop function, which leads to stackoverflow. We can implement our custom Drop trait for List to prevent this, the following code seems to solve this problem:

impl<T, P> Drop for List<T, P>
where
    P: SharedPointerKind,
{
    fn drop(&mut self) {
        let mut head = self.head.take();
        while let Some(node) = head {
            if let Ok(mut node) = SharedPointer::try_unwrap(node) {
                head = node.next.take();
            }
            else {
                break;
            }
        }
    }
}
@lulitao1997
Copy link
Contributor Author

lulitao1997 commented Jul 2, 2019

can i make a pull request for this? :)

@orium
Copy link
Owner

orium commented Jul 2, 2019

Hi @lulitao1997. A PR will be more than welcome :)

@orium
Copy link
Owner

orium commented Jul 3, 2019

Fixed by #47

@orium orium closed this as completed Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants