1
1
#include " base_object.h"
2
2
#include " env-inl.h"
3
+ #include " memory_tracker-inl.h"
3
4
#include " node_messaging.h"
4
5
#include " node_realm-inl.h"
5
6
@@ -24,13 +25,11 @@ BaseObject::BaseObject(Realm* realm, Local<Object> object)
24
25
CHECK_EQ (false , object.IsEmpty ());
25
26
CHECK_GE (object->InternalFieldCount (), BaseObject::kInternalFieldCount );
26
27
SetInternalFields (realm->isolate_data (), object, static_cast <void *>(this ));
27
- realm->AddCleanupHook (DeleteMe, static_cast <void *>(this ));
28
- realm->modify_base_object_count (1 );
28
+ realm->TrackBaseObject (this );
29
29
}
30
30
31
31
BaseObject::~BaseObject () {
32
- realm ()->modify_base_object_count (-1 );
33
- realm ()->RemoveCleanupHook (DeleteMe, static_cast <void *>(this ));
32
+ realm ()->UntrackBaseObject (this );
34
33
35
34
if (has_pointer_data ()) [[unlikely]] {
36
35
PointerData* metadata = pointer_data ();
@@ -147,12 +146,11 @@ void BaseObject::increase_refcount() {
147
146
persistent_handle_.ClearWeak ();
148
147
}
149
148
150
- void BaseObject::DeleteMe (void * data) {
151
- BaseObject* self = static_cast <BaseObject*>(data);
152
- if (self->has_pointer_data () && self->pointer_data ()->strong_ptr_count > 0 ) {
153
- return self->Detach ();
149
+ void BaseObject::DeleteMe () {
150
+ if (has_pointer_data () && pointer_data ()->strong_ptr_count > 0 ) {
151
+ return Detach ();
154
152
}
155
- delete self ;
153
+ delete this ;
156
154
}
157
155
158
156
bool BaseObject::IsDoneInitializing () const {
@@ -171,4 +169,17 @@ bool BaseObject::IsNotIndicativeOfMemoryLeakAtExit() const {
171
169
return IsWeakOrDetached ();
172
170
}
173
171
172
+ void BaseObjectList::Cleanup () {
173
+ while (!IsEmpty ()) {
174
+ BaseObject* bo = PopFront ();
175
+ bo->DeleteMe ();
176
+ }
177
+ }
178
+
179
+ void BaseObjectList::MemoryInfo (node::MemoryTracker* tracker) const {
180
+ for (auto bo : *this ) {
181
+ if (bo->IsDoneInitializing ()) tracker->Track (bo);
182
+ }
183
+ }
184
+
174
185
} // namespace node
0 commit comments