File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -73,11 +73,20 @@ where
73
73
I :: Item : Sample ,
74
74
{
75
75
fn drop ( & mut self ) {
76
+ // This is necessary to prevent stack overflows deallocating long chains of the mutually
77
+ // recursive `Frame` and `FrameData` types. This iteratively traverses as much of the
78
+ // chain as needs to be deallocated, and repeatedly "pops" the head off the list. This
79
+ // solves the problem, as when the time comes to actually deallocate the `FrameData`,
80
+ // the `next` field will contain a `Frame::End`, or an `Arc` with additional references,
81
+ // so the depth of recursive drops will be bounded.
76
82
loop {
77
83
if let Ok ( arc_next) = self . next . get_mut ( ) {
78
84
if let Some ( next_ref) = Arc :: get_mut ( arc_next) {
85
+ // This allows us to own the next Frame.
79
86
let next = mem:: replace ( next_ref, Frame :: End ) ;
80
87
if let Frame :: Data ( next_data) = next {
88
+ // Swap the current FrameData with the next one, allowing the current one
89
+ // to go out of scope.
81
90
mem:: replace ( self , next_data) ;
82
91
} else {
83
92
break ;
You can’t perform that action at this time.
0 commit comments