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