<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>freeing memory</title>
		<link>http://www.allegro.cc/forums/view/611122</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 02 Oct 2012 07:54:49 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do I have to call al_destroy_bitmap every time I do this:</p><p><span class="source-code"> img1 <span class="k3">=</span> img2</span></p><p>When ever I do it increases my memory usage everytime I do that unless I call that on it. And when I do use it, it crashes but it isn&#39;t empty.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Mon, 24 Sep 2012 18:22:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If img1 is an ALLEGRO_BITMAP, that creates a leak, so yes, you want to call <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a></span> on img1. But you have to make sure you don&#39;t call <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a></span> on the same address twice. Also note, <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a></span> does not set the variable you pass to it to 0 or NULL. If you want that, you have to set it yourself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 24 Sep 2012 18:28:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh I didn&#39;t know that. I&#39;ll give it a shot. </p><p>EDIT: Its still crashing.</p><p>1. image is null<br />2. assign image to image<br />3. destroy it(if image != NULL) - crashes here<br />4. make it null<br />5. assign another image to image
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Mon, 24 Sep 2012 18:41:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Every ALLEGRO_BITMAP* you create, you should destroy. It doesn&#39;t matter how or when you assign it to another pointer as long as you don&#39;t lose a reference to a created bitmap before you destroy it.</p><p>Ex:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> created1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a><span class="k2">(</span><span class="n">800</span>,<span class="n">600</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> created2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"hero.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> shallow_reference1 <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span>shallow_reference1 <span class="k3">=</span> created1<span class="k2">;</span><span class="c">// fine, does not create or destroy memory</span>
<span class="number">  7</span>shallow_reference1 <span class="k3">=</span> created2<span class="k2">;</span><span class="c">// fine, same thing</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="c">// This next line would be bad :</span>
<span class="number"> 10</span>created1 <span class="k3">=</span> created2<span class="k2">;</span><span class="c">// OOPS we just leaked the bitmap referenced by created1</span>
<span class="number"> 11</span>
<span class="number"> 12</span><span class="c">// Clean up when done</span>
<span class="number"> 13</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>created1<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>created2<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>
<span class="number"> 16</span><span class="c">// This would be bad :</span>
<span class="number"> 17</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>created1<span class="k2">)</span><span class="k2">;</span><span class="c">// Already did this, it will crash</span>
<span class="number"> 18</span>
<span class="number"> 19</span>created2 <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 20</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>created2<span class="k2">)</span><span class="k2">;</span><span class="c">// Could be fine, depends on what Allegro does with a null pointer.</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 24 Sep 2012 22:36:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So how to do I make it not crash? I always destroy a bitmap when I assign it if its not null.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Tue, 25 Sep 2012 03:43:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m probably missing something here, but you don&#39;t want to destroy it until you&#39;re done displaying it or whatever.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 25 Sep 2012 03:47:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When I monitor my programs memory usage, everytime I reassign an ALLEGRO_BITMAP my memory usage goes up. So I destroy the bitmap before I reassign it, but sometimes it crashes and I don&#39;t know why.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Tue, 25 Sep 2012 03:50:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611122/966784#target">shadyvillian</a> said:</div><div class="quote"><p> So I destroy the bitmap before I reassign it, but sometimes it crashes and I don&#39;t know why.</p></div></div><p>When you destroy a bitmap, the memory becomes available for other uses.  When it doesn&#39;t crash, it hasn&#39;t been reused and overwritten to something else yet.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 25 Sep 2012 03:55:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t destroy the bitmaps until you are done using them, and only do it once. This crap about memory use going up when you assign a pointer is ridiculous. Assigning a pointer takes exactly zero memory to perform. Whatever you&#39;re using to measure your memory use is not accurate.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 25 Sep 2012 07:31:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Post the code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Tue, 25 Sep 2012 08:01:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m getting complete random crashes when I go to draw the image sometimes without an errors going off.</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">struct</span> MemoryStruct chunk<span class="k2">;</span>
<span class="number">  2</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a> <span class="k3">*</span>file <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  3</span>    CURLcode error<span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>    <span class="k1">if</span><span class="k2">(</span>imgBuffer <span class="k3">!</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number">  6</span>    <span class="k2">{</span>
<span class="number">  7</span>        <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>imgBuffer<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>    <span class="k2">}</span>
<span class="number">  9</span>
<span class="number"> 10</span>    imgBuffer <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>    chunk.memory <span class="k3">=</span> <span class="k2">(</span><span class="k1">char</span><span class="k3">*</span><span class="k2">)</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_551.html" target="_blank">malloc</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    chunk.size <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 14</span>
<span class="number"> 15</span>    curl_easy_setopt<span class="k2">(</span>curl, CURLOPT_USERPWD, <span class="s">"user:password"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>    curl_easy_setopt<span class="k2">(</span>curl,CURLOPT_URL, url.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>    curl_easy_setopt<span class="k2">(</span>curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>    curl_easy_setopt<span class="k2">(</span>curl, CURLOPT_WRITEDATA, <span class="k2">(</span><span class="k1">void</span> <span class="k3">*</span><span class="k2">)</span><span class="k3">&amp;</span>chunk<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    error <span class="k3">=</span> curl_easy_perform<span class="k2">(</span>curl<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span>    <span class="k1">if</span><span class="k2">(</span>error <span class="k3">!</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
<span class="number"> 22</span>    <span class="k2">{</span>
<span class="number"> 23</span>        Framework::ShowMessageBox<span class="k2">(</span><span class="s">"Error"</span>, <span class="s">"Failed to download image"</span>, ALLEGRO_MESSAGEBOX_ERROR<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>    <span class="k2">}</span>
<span class="number"> 25</span>
<span class="number"> 26</span>    file <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_open_memfile"><span class="a">al_open_memfile</span></a><span class="k2">(</span>chunk.memory, chunk.size, <span class="s">"rw"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 27</span>
<span class="number"> 28</span>    <span class="k1">if</span><span class="k2">(</span>file <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number"> 29</span>    <span class="k2">{</span>
<span class="number"> 30</span>        cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"failed to open file"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 31</span>    <span class="k2">}</span>
<span class="number"> 32</span>
<span class="number"> 33</span>    imgBuffer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap_f"><span class="a">al_load_bitmap_f</span></a><span class="k2">(</span>file, <span class="s">".jpg"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 34</span>
<span class="number"> 35</span>    <span class="k1">if</span><span class="k2">(</span>imgBuffer <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number"> 36</span>    <span class="k2">{</span>
<span class="number"> 37</span>        cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"failed to load bitmap"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 38</span>    <span class="k2">}</span>
<span class="number"> 39</span>
<span class="number"> 40</span>    <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 41</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_350.html" target="_blank">free</a><span class="k2">(</span>chunk.memory<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 42</span>
<span class="number"> 43</span>    <span class="k1">return</span> imgBuffer<span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Sun, 30 Sep 2012 20:40:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I meant all of the code, or at least a complete program that reproduces the issue. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> The more I speculate on what is going on here the more wrong I become. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 30 Sep 2012 21:15:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The program is like 5000 lines though.... I could attach it if you want to see it. I hate when errors like this happen because my memory isn&#39;t increasing anymore but the bitmap is becoming invalid or something and it randomly crashes on draw.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Mon, 01 Oct 2012 03:55:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is the program single-threaded?<br />Can we see the draw function?</p><p>Try searching for imgBuffer in all your code, and make sure you&#39;re not accidentally destroying it somewhere or setting it to NULL.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Schyfis)</author>
		<pubDate>Mon, 01 Oct 2012 13:27:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ImgBuffer isn&#39;t being drawn at all its just to hold the bitmap that al_load_bimtap_f loads because if I just return al_load_bitmap_f my memory usage goes up everytime(I think not using imgBuffer stops the crashing maybe). I&#39;m just confused on what to do. If I used imgBuffer I get Random crashes if I don&#39;t i get a memory leak...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Mon, 01 Oct 2012 18:05:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When I use bitmaps with Allegro 5, I do the following:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="c">// Make sure you assign it NULL to initialize it first</span>
<span class="number">  2</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span>bitmap<span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a><span class="k2">(</span><span class="n">800</span>,<span class="n">600</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span><span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>bitmap<span class="k2">)</span> <span class="k2">{</span> <span class="c">// always check return values</span>
<span class="number">  6</span>   <span class="c">//failed, print error message and exit here</span>
<span class="number">  7</span><span class="k2">}</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="c">// now if I want to load something else into that bitmap</span>
<span class="number"> 10</span><span class="c">// I will destroy it first and set it to NULL before using it again</span>
<span class="number"> 11</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>bitmap<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>bitmap <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>bitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"myimage.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span><span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>bitmap<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 16</span>   <span class="c">//failed, print error message and exit here</span>
<span class="number"> 17</span><span class="k2">}</span>
</div></div><p>

Basically, don&#39;t assume, check all return values, set the initial value to NULL, if you destroy a bitmap, even if you plan to reuse it, reset it to NULL, otherwise if you check to see if it failed to load, and it contains the address of the last bitmap still, your check won&#39;t be accurate and you&#39;ll have problems.  This way you <b>know</b> it is NULL unless it loads safely because that is what you set it to.</p><p>Edit: I am curious, how do you check for memory leaks?  I use CodeBlocks with MinGW, never done that before but want to.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611122/966808#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>Don&#39;t destroy the bitmaps until you are done using them, and only do it once. This crap about memory use going up when you assign a pointer is ridiculous. Assigning a pointer takes exactly zero memory to perform. Whatever you&#39;re using to measure your memory use is not accurate.
</p></div></div><p>

It seems to me that if you assign a new address to a pointer without first freeing up the memory that it is currently pointing to, than you&#39;ll create a leak, I think this is what people are talking about.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Mon, 01 Oct 2012 20:22:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611122/967216#target">shadyvillian</a> said:</div><div class="quote"><p>
ImgBuffer isn&#39;t being drawn at all its just to hold the bitmap that al_load_bimtap_f loads because if I just return al_load_bitmap_f my memory usage goes up everytime(I think not using imgBuffer stops the crashing maybe). I&#39;m just confused on what to do. If I used imgBuffer I get Random crashes if I don&#39;t i get a memory leak...
</p></div></div><p>
OK, I see what you&#39;re doing now and I&#39;d recommend against it. What you should be doing is passing ownership of that <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a></span> object back to the caller. What that basically means is that the caller is now responsible for destroying that bitmap when it&#39;s done with it (unless it happens to also pass the responsibility along). In any case, your &quot;constructor&quot; or loader function should not be attempting to remember previously loaded bitmaps and release them like that. Do you understand?
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611122/967225#target">NiteHackr</a> said:</div><div class="quote"><p>
...otherwise if you check to see if it failed to load, and it contains the address of the last bitmap still, your check won&#39;t be accurate and you&#39;ll have problems.
</p></div></div><p>
Technically all of the create/load functions for BITMAPs return NULL when they fail so you will reset said pointers to NULL in those cases, but if somebody happens to come along and stick 20 lines of code between <span class="source-code">destroy</span> and <span class="source-code">load</span> then it might get lost in the clutter. Better safe than sorry, IMO. <span class="source-code">bam_free</span> from my C utility library accepts a pointer to a pointer. It frees the memory and sets the pointer to zero for you. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Mon, 01 Oct 2012 20:53:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok I think I get it now. I think I fixed it by integrating the function into the Image class so it works with the bitmap directly instead of just making a bitmap returning it into the image loader function(that returned the bitmap into the load function then assigned the bitmap from the parameter into the classes bitmap). I gets pretty confusing when you try to make everything object oriented and organized sometimes I guess <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Mon, 01 Oct 2012 21:19:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I find that things get simpler when you start orienting things in an object-like way.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Luiji99)</author>
		<pubDate>Mon, 01 Oct 2012 22:29:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611122/967231#target">bamccaig</a> said:</div><div class="quote"><p>It frees the memory and sets the pointer to zero for you. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p></div></div><p>

That was something I had considered as well.  Having it check to see if it is NULL, and if not, free it first.  I always immediately destroy any bitmaps when I am done with them and set them to NULL so it isn&#39;t an issue.</p><p>I&#39;ve done this in my own code where I had a temporary bitmap I was using to load in sprite sheets then divide them up into arrays (to avoid 3D filtering problems on tiled games).  I just destroy the bitmap and set it to NULL when I am done loading etc... for each set of sprites/tiles on my latest project.</p><p>I read that the Allegro functions return NULL, but, like you, I feel safer setting it myself.  Just one little line of code for peace of mind. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 02 Oct 2012 00:50:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A better alternative for C++ is using smart pointers i.e., <span class="source-code">boost::shared_ptr<span class="k3">&lt;</span>T&gt;</span>, which will handle the cleanup for you automatically. This is probably something that the OP should look into as well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Tue, 02 Oct 2012 01:44:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That sounds nice.  I&#39;m not doing much in C++ yet myself, but I&#39;ll try and keep that in mind when I do.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 02 Oct 2012 05:04:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611122/966702#target">shadyvillian</a> said:</div><div class="quote"><p>Do I have to call al_destroy_bitmap every time I do this: img1 = img2</p></div></div><p>

If <span class="source-code">img1</span> and <span class="source-code">img2</span> are `ALLEGRO_BITMAP*`s, (which I&#39;m guessing they are), then it&#39;s important to understand that you are not making a copy of the bitmap image. You are only making a copy of the pointer to the image.</p><p>eg.
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> img1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"myimage.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span><span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>img1<span class="k2">)</span>
<span class="number">  3</span><span class="k2">{</span>
<span class="number">  4</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>stderr, <span class="s">"failed to load myimage.png\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span><span class="k2">}</span>
<span class="number">  7</span>
<span class="number">  8</span><span class="c">// img1 is loaded and ready to use.</span>
<span class="number">  9</span>
<span class="number"> 10</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> img2 <span class="k3">=</span> img1<span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span><span class="c">// img2 now points to the same bitmap as img1. So either of these can now be used</span>
<span class="number"> 13</span>
<span class="number"> 14</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>img1<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>
<span class="number"> 16</span><span class="c">// We have now destroyed the bitmap which both img1 and img2 are pointing to.</span>
<span class="number"> 17</span><span class="c">// So img1 _and_ img2 both now point to garbage.</span>
<span class="number"> 18</span>
<span class="number"> 19</span><a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>img2, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// bad!</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="c">// this will probably crash, because the image pointed to by img2 has been deleted.</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Karadoc ~~)</author>
		<pubDate>Tue, 02 Oct 2012 07:54:49 +0000</pubDate>
	</item>
</rss>
