File: //usr/share/gtk-doc/html/gdk-pixbuf/gdk-pixbuf-refcounting.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Reference Counting and Memory Mangement</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="index.html" title="The gdk-pixbuf Library">
<link rel="up" href="rn01.html" title="API Reference">
<link rel="prev" href="gdk-pixbuf-gdk-pixbuf.html" title="The GdkPixbuf Structure">
<link rel="next" href="gdk-pixbuf-file-loading.html" title="File Loading">
<meta name="generator" content="GTK-Doc V1.6 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="reference" href="rn01.html" title="API Reference">
<link rel="reference" href="rn02.html" title="Tools Reference">
<link rel="index" href="ix01.html" title="Index">
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
<link rel="appendix" href="apa.html" title="Appendix A. Porting applications from Imlib to gdk-pixbuf">
<link rel="appendix" href="license.html" title="Appendix B. License">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="gdk-pixbuf-gdk-pixbuf.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="rn01.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">The <span class="application">gdk-pixbuf</span> Library</th>
<td><a accesskey="n" href="gdk-pixbuf-file-loading.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3095034" class="shortcut">Top</a>
 | 
<a href="#id3095123" class="shortcut">Description</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="gdk-pixbuf-refcounting"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id3095034"></a><span class="refentrytitle">Reference Counting and Memory Mangement</span>
</h2>
<p>Reference Counting and Memory Mangement —
Functions for reference counting and memory management on pixbufs.</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">
#include <gdk-pixbuf/gdk-pixbuf.h>
<a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf">GdkPixbuf</a>* <a href="gdk-pixbuf-refcounting.html#gdk-pixbuf-ref">gdk_pixbuf_ref</a> (<a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf">GdkPixbuf</a> *pixbuf);
void <a href="gdk-pixbuf-refcounting.html#gdk-pixbuf-unref">gdk_pixbuf_unref</a> (<a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf">GdkPixbuf</a> *pixbuf);
void (<a href="gdk-pixbuf-refcounting.html#GdkPixbufDestroyNotify">*GdkPixbufDestroyNotify</a>) (<a
href="../glib/glib-Basic-Types.html#guchar"
>guchar</a> *pixels,
<a
href="../glib/glib-Basic-Types.html#gpointer"
>gpointer</a> data);
</pre>
</div>
<div class="refsect1" lang="en">
<a name="id3095123"></a><h2>Description</h2>
<p>
<a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a> structures are reference counted. This means that an
application can share a single pixbuf among many parts of the
code. When a piece of the program needs to keep a pointer to a
pixbuf, it should add a reference to it by calling <a
href="../gobject/gobject-The-Base-Object-Type.html#g-object-ref"
><code class="function">g_object_ref()</code></a>.
When it no longer needs the pixbuf, it should subtract a reference
by calling <a
href="../gobject/gobject-The-Base-Object-Type.html#g-object-unref"
><code class="function">g_object_unref()</code></a>. The pixbuf will be destroyed when
its reference count drops to zero. Newly-created <a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a>
structures start with a reference count of one.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
As <a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a> is derived from <a
href="../gobject/gobject-The-Base-Object-Type.html#GObject"
><span class="type">GObject</span></a> now, <a href="gdk-pixbuf-refcounting.html#gdk-pixbuf-ref"><code class="function">gdk_pixbuf_ref()</code></a> and
<a href="gdk-pixbuf-refcounting.html#gdk-pixbuf-unref"><code class="function">gdk_pixbuf_unref()</code></a> are deprecated in favour of <a
href="../gobject/gobject-The-Base-Object-Type.html#g-object-ref"
><code class="function">g_object_ref()</code></a>
and <a
href="../gobject/gobject-The-Base-Object-Type.html#g-object-unref"
><code class="function">g_object_unref()</code></a> resp.
</p>
</div>
<p>
<span class="emphasis"><em>Finalizing</em></span> a pixbuf means to free its pixel
data and to free the <a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a> structure itself. Most of the
library functions that create <a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a> structures create the
pixel data by themselves and define the way it should be freed;
you do not need to worry about those. The only function that lets
you specify how to free the pixel data is
<a href="gdk-pixbuf-creating.html#gdk-pixbuf-new-from-data"><code class="function">gdk_pixbuf_new_from_data()</code></a>. Since you pass it a pre-allocated
pixel buffer, you must also specify a way to free that data. This
is done with a function of type <a href="gdk-pixbuf-refcounting.html#GdkPixbufDestroyNotify"><span class="type">GdkPixbufDestroyNotify</span></a>. When a
pixbuf created with <a href="gdk-pixbuf-creating.html#gdk-pixbuf-new-from-data"><code class="function">gdk_pixbuf_new_from_data()</code></a> is finalized, your
destroy notification function will be called, and it is its
responsibility to free the pixel array.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id3095315"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id3095325"></a><h3>
<a name="gdk-pixbuf-ref"></a>gdk_pixbuf_ref ()</h3>
<a class="indexterm" name="id3095341"></a><pre class="programlisting"><a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf">GdkPixbuf</a>* gdk_pixbuf_ref (<a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf">GdkPixbuf</a> *pixbuf);</pre>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Warning</h3>
<p><code class="literal">gdk_pixbuf_ref</code> is deprecated and should not be used in newly-written code. Use <a
href="../gobject/gobject-The-Base-Object-Type.html#g-object-ref"
><code class="function">g_object_ref()</code></a>.</p>
</div>
<p>
Adds a reference to a pixbuf.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>pixbuf</code></em> :</span></td>
<td> A pixbuf.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
<td> The same as the <em class="parameter"><code>pixbuf</code></em> argument.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3095430"></a><h3>
<a name="gdk-pixbuf-unref"></a>gdk_pixbuf_unref ()</h3>
<a class="indexterm" name="id3095446"></a><pre class="programlisting">void gdk_pixbuf_unref (<a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf">GdkPixbuf</a> *pixbuf);</pre>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Warning</h3>
<p><code class="literal">gdk_pixbuf_unref</code> is deprecated and should not be used in newly-written code. Use <a
href="../gobject/gobject-The-Base-Object-Type.html#g-object-unref"
><code class="function">g_object_unref()</code></a>.</p>
</div>
<p>
Removes a reference from a pixbuf.</p>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td>
<span class="term"><em class="parameter"><code>pixbuf</code></em> :</span></td>
<td> A pixbuf.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3095519"></a><h3>
<a name="GdkPixbufDestroyNotify"></a>GdkPixbufDestroyNotify ()</h3>
<a class="indexterm" name="id3095532"></a><pre class="programlisting">void (*GdkPixbufDestroyNotify) (<a
href="../glib/glib-Basic-Types.html#guchar"
>guchar</a> *pixels,
<a
href="../glib/glib-Basic-Types.html#gpointer"
>gpointer</a> data);</pre>
<p>
A function of this type is responsible for freeing the pixel array
of a pixbuf. The <a href="gdk-pixbuf-creating.html#gdk-pixbuf-new-from-data"><code class="function">gdk_pixbuf_new_from_data()</code></a> function lets you
pass in a pre-allocated pixel array so that a pixbuf can be
created from it; in this case you will need to pass in a function
of <a href="gdk-pixbuf-refcounting.html#GdkPixbufDestroyNotify"><span class="type">GdkPixbufDestroyNotify</span></a> so that the pixel data can be freed
when the pixbuf is finalized.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>pixels</code></em> :</span></td>
<td>The pixel array of the pixbuf that is being finalized.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>data</code></em> :</span></td>
<td>User closure data.
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="refsect1" lang="en">
<a name="id3095627"></a><h2>See Also</h2>
<p>
<a href="gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a>, <a href="gdk-pixbuf-creating.html#gdk-pixbuf-new-from-data"><code class="function">gdk_pixbuf_new_from_data()</code></a>.
</p>
</div>
</div>
</body>
</html>