diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index ff6f8b5ea9d..d46d5a4f926 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -176,7 +176,7 @@ void JsonValue::clear() { switch (m_type) { case Type::String: - m_value.as_string->deref(); + m_value.as_string->unref(); break; case Type::Object: delete m_value.as_object; diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index a30a3c96bc1..426c4f5dcac 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -46,10 +46,10 @@ inline void ref_if_not_null(T* ptr) } template -inline void deref_if_not_null(T* ptr) +inline void unref_if_not_null(T* ptr) { if (ptr) - ptr->deref(); + ptr->unref(); } template @@ -103,7 +103,7 @@ public: } ~NonnullRefPtr() { - deref_if_not_null(m_ptr); + unref_if_not_null(m_ptr); m_ptr = nullptr; #ifdef SANITIZE_PTRS if constexpr (sizeof(T*) == 8) diff --git a/AK/RefCounted.h b/AK/RefCounted.h index 17241f06eaf..7926de73211 100644 --- a/AK/RefCounted.h +++ b/AK/RefCounted.h @@ -87,7 +87,7 @@ protected: template class RefCounted : public RefCountedBase { public: - void deref() + void unref() { deref_base(); if (m_ref_count == 0) { diff --git a/AK/RefPtr.h b/AK/RefPtr.h index ae297576b28..b942cc0b78f 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -198,7 +198,7 @@ public: void clear() { - deref_if_not_null(m_ptr); + unref_if_not_null(m_ptr); m_ptr = nullptr; } diff --git a/AK/Tests/TestNonnullRefPtr.cpp b/AK/Tests/TestNonnullRefPtr.cpp index 1cd183c0e3f..77d9fe777a5 100644 --- a/AK/Tests/TestNonnullRefPtr.cpp +++ b/AK/Tests/TestNonnullRefPtr.cpp @@ -40,7 +40,7 @@ TEST_CASE(basics) EXPECT_EQ(object->ref_count(), 1); object->ref(); EXPECT_EQ(object->ref_count(), 2); - object->deref(); + object->unref(); EXPECT_EQ(object->ref_count(), 1); { diff --git a/AK/Tests/TestRefPtr.cpp b/AK/Tests/TestRefPtr.cpp index 8aafe0547b8..633af6f70f5 100644 --- a/AK/Tests/TestRefPtr.cpp +++ b/AK/Tests/TestRefPtr.cpp @@ -40,7 +40,7 @@ TEST_CASE(basics) EXPECT_EQ(object->ref_count(), 1); object->ref(); EXPECT_EQ(object->ref_count(), 2); - object->deref(); + object->unref(); EXPECT_EQ(object->ref_count(), 1); { diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index b1679acad44..578e0b47f11 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -105,7 +105,12 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); + auto window = GWindow::construct(); + window->set_title("System Monitor"); + window->set_rect(20, 200, 680, 400); + auto keeper = GWidget::construct(); + window->set_main_widget(keeper); keeper->set_layout(make(Orientation::Vertical)); keeper->set_fill_with_background_color(true); keeper->layout()->set_margins({ 4, 4, 4, 4 }); @@ -140,7 +145,7 @@ int main(int argc, char** argv) process_table_view->refresh(); if (auto* memory_stats_widget = MemoryStatsWidget::the()) memory_stats_widget->refresh(); - }); + }, window); auto kill_action = GAction::create("Kill process", { Mod_Ctrl, Key_K }, GraphicsBitmap::load_from_file("/res/icons/kill16.png"), [process_table_view](const GAction&) { pid_t pid = process_table_view->selected_pid(); @@ -164,11 +169,6 @@ int main(int argc, char** argv) toolbar->add_action(stop_action); toolbar->add_action(continue_action); - auto window = GWindow::construct(); - window->set_title("System Monitor"); - window->set_rect(20, 200, 680, 400); - window->set_main_widget(keeper); - auto menubar = make(); auto app_menu = GMenu::construct("System Monitor"); app_menu->add_action(GCommonActions::make_quit_action([](auto&) { diff --git a/Documentation/SmartPointers.md b/Documentation/SmartPointers.md index 29104ecddfd..8410e6cdfaf 100644 --- a/Documentation/SmartPointers.md +++ b/Documentation/SmartPointers.md @@ -35,7 +35,7 @@ Shared ownership is implemented via reference counting. NonnullRefPtr is a special variant of RefPtr with one additional property: it cannot be null. NonnullRefPtr is suitable as a return type from functions that are guaranteed to never return null, and as an argument type where the argument may not be null. In other words, if RefPtr is "\*", then NonnullRefPtr is "&". -Objects can only be held by RefPtr if they meet certain criteria. Specifically, they need to implement the functions `ref()` and `deref()`. +Objects can only be held by RefPtr if they meet certain criteria. Specifically, they need to implement the functions `ref()` and `unref()`. To make a class T reference counted, you can simply make it inherit from RefCounted. This will add all the necessary pieces to T. diff --git a/Kernel/VM/PhysicalPage.h b/Kernel/VM/PhysicalPage.h index 66c714795a8..2d916de1dfe 100644 --- a/Kernel/VM/PhysicalPage.h +++ b/Kernel/VM/PhysicalPage.h @@ -46,7 +46,7 @@ public: ++m_retain_count; } - void deref() + void unref() { ASSERT(m_retain_count); if (!--m_retain_count) { diff --git a/Libraries/LibGUI/GVariant.cpp b/Libraries/LibGUI/GVariant.cpp index 94f144636dc..cfe43a70adf 100644 --- a/Libraries/LibGUI/GVariant.cpp +++ b/Libraries/LibGUI/GVariant.cpp @@ -61,13 +61,13 @@ void GVariant::clear() { switch (m_type) { case Type::String: - AK::deref_if_not_null(m_value.as_string); + AK::unref_if_not_null(m_value.as_string); break; case Type::Bitmap: - AK::deref_if_not_null(m_value.as_bitmap); + AK::unref_if_not_null(m_value.as_bitmap); break; case Type::Icon: - AK::deref_if_not_null(m_value.as_icon); + AK::unref_if_not_null(m_value.as_icon); break; default: break; diff --git a/Libraries/LibHTML/TreeNode.h b/Libraries/LibHTML/TreeNode.h index bf2e567edf5..f0550b9b21e 100644 --- a/Libraries/LibHTML/TreeNode.h +++ b/Libraries/LibHTML/TreeNode.h @@ -48,7 +48,7 @@ public: ++m_ref_count; } - void deref() + void unref() { ASSERT(m_ref_count); if (!--m_ref_count) { @@ -60,7 +60,7 @@ public: for (auto* child = m_first_child; child; child = next_child) { next_child = child->m_next_sibling; child->m_parent = nullptr; - child->deref(); + child->unref(); } delete static_cast(this); } @@ -221,7 +221,7 @@ inline NonnullRefPtr TreeNode::remove_child(NonnullRefPtr node, bool ca if (call_removed_from) node->removed_from(static_cast(*this)); - node->deref(); + node->unref(); return node; } diff --git a/Libraries/LibThread/BackgroundAction.h b/Libraries/LibThread/BackgroundAction.h index c5f3a6de62e..076e3d3bff7 100644 --- a/Libraries/LibThread/BackgroundAction.h +++ b/Libraries/LibThread/BackgroundAction.h @@ -81,11 +81,11 @@ private: if (m_on_complete) { CEventLoop::main().post_event(*this, make([this](CObject&) { m_on_complete(m_result.release_value()); - this->deref(); + this->unref(); })); CEventLoop::main().wake(); } else - this->deref(); + this->unref(); }); }