@@ -44,6 +44,13 @@ class NodeBIO;
4444 * // Node name and size comes from the MemoryInfoName and SelfSize of
4545 * // AnotherRetainerClass
4646 * tracker->TrackField("another_retainer", another_retainer_);
47+ *
48+ * // Add non_pointer_retainer as a separate node into the graph
49+ * // and track its memory information recursively.
50+ * // Note that we need to make sure its size is not accounted in
51+ * // ExampleRetainer::SelfSize().
52+ * tracker->TrackField("non_pointer_retainer", &non_pointer_retainer_);
53+ *
4754 * // Specify node name and size explicitly
4855 * tracker->TrackFieldWithSize("internal_member",
4956 * internal_member_.size(),
@@ -60,9 +67,12 @@ class NodeBIO;
6067 * return "ExampleRetainer";
6168 * }
6269 *
63- * // Or use SET_SELF_SIZE(ExampleRetainer)
70+ * // Classes that only want to return its sizeof() value can use the
71+ * // SET_SELF_SIZE(Class) macro instead.
6472 * size_t SelfSize() const override {
65- * return sizeof(ExampleRetainer);
73+ * // We need to exclude the size of non_pointer_retainer so that
74+ * // we can track it separately in ExampleRetainer::MemoryInfo().
75+ * return sizeof(ExampleRetainer) - sizeof(NonPointerRetainerClass);
6676 * }
6777 *
6878 * // Note: no need to implement these two methods when implementing
@@ -71,8 +81,10 @@ class NodeBIO;
7181 * v8::Local<v8::Object> WrappedObject() const override {
7282 * return node::PersistentToLocal::Default(wrapped_);
7383 * }
84+ *
7485 * private:
75- * AnotherRetainerClass another_retainer_;
86+ * AnotherRetainerClass* another_retainer_;
87+ * NonPointerRetainerClass non_pointer_retainer;
7688 * InternalClass internal_member_;
7789 * std::vector<uv_async_t> vector_;
7890 * node::Persistent<Object> target_;
0 commit comments