Fix invalid memory reads when GC is on
Merge pull request #927 from sjinks/garbage-collection

[BUG] Fix invalid memory reads when GC is on