Changes between Version 2 and Version 3 of GRefPtr


Ignore:
Timestamp:
Jan 20, 2014 3:18:26 AM (8 years ago)
Author:
Adrian Perez de Castro
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GRefPtr

    v2 v3  
    1818{{{
    1919#!cpp
    20 GRefPtr<GtkWidget> widget;
     20GRefPtr<GMainContext> context;
    2121// Check always succeeds, nullptr is the default value.
    22 ASSERT(!widget);
     22ASSERT(!context);
    2323}}}
    2424
    25 It is also possible to pass an initial value to the constructor — it can be both a raw pointer or a `GRefPtr` of the same type:
    26 {{{
    27 #!cpp
    28 void doWithWidget(GtkWidget* widget) {
    29     GRefPtr<GtkWidget> widgetLocal1(widget); // Increases the reference counter of “widget”
    30     GRefPtr<GtkWidget> widgetLocal2(widgetLocal1); // ...and again.
    31 }
    32 }}}
     25=== Destruction ===
    3326
    3427When a `GRefPtr<T>` goes is destroyed, it decreases the reference count of the object it holds.
    3528
    36 === Adopting a pointer ===
    3729
    38 Sometimes it is desirable to store a pointer in a `GRefPtr` without increasing the reference counter. The main use case is assigning a newly created instance to a `GRefPtr`: the newly created instance already has a reference count of ''one'' and assigning it to a `GRefPtr` would increase the reference count to ''two'', which would be incorrect. To avoid this, the `adoptGRef()` helper function is provided. This function creates a `GRefPtr` without increasing the reference counter of the object it holds. This is incorrect:
     30=== Adopting a reference ===
     31
     32Sometimes it is desirable to store a pointer in a `GRefPtr` without increasing the reference counter. The main use case is assigning a newly created instance to a `GRefPtr`: the newly created instance already has a reference count of ''one'' and assigning it to a `GRefPtr` would increase the reference count to ''two'', which would be incorrect (and very likely would cause a leak). To avoid this, the `adoptGRef()` helper function is provided. This function creates a `GRefPtr` without increasing the reference counter of the object it holds. This is incorrect:
    3933{{{
    4034#!cpp