Skip to content

Commit 8051f8a

Browse files
albanDpytorchmergebot
authored andcommitted
Fix Storage destruction GC tracking (pytorch#94051)
Pull Request resolved: pytorch#94051 Approved by: https://github.com/Skylion007, https://github.com/malfet
1 parent 203b2ca commit 8051f8a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

torch/csrc/Storage.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ PyObject* THPStorage_New(c10::intrusive_ptr<c10::StorageImpl> ptr) {
4141

4242
static void THPStorage_subclass_dealloc(PyObject* self) {
4343
THPStorage* _self = (THPStorage*)self;
44+
// Some subclass of StorageBase are GC-tracked objects even
45+
// though the base class is not.
46+
auto* type = Py_TYPE(self);
47+
if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC) != 0) {
48+
PyObject_GC_UnTrack(self);
49+
}
4450
if (_self->cdata) {
4551
c10::raw::intrusive_ptr::decref(_self->cdata);
4652
}

0 commit comments

Comments
 (0)