<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>correct way to delete?</title>
<description> in my game engine the images to be drawn are stored in a vector similarly to libwiigui (most of my graphics coding is inspired by libwiigui) and i want to clear the vector of images, since the vector is a set of pointers i thought it would be correct to use delete but this seems to cause a hang in the code probably because i have kept to my php habits of being reckless

i have put all the required info below including the structs for the variables in question:

typedef struct element{
SDL_Surface *image; //actual image for element
int x; //x pos
int y; //y pos
int xvel; //velocity in x direction in pixels
int yvel; //velocity in y direction in pixels
int interval; //sets movements speed i.e setting to 50 would mean one movement per 50ms, allows slow movements
SDL_Rect area; //part of image to display, default to entire image, allows tilesets for animating
};

vector&amp;lt;element*&amp;gt; elements;
vector&amp;lt;element*&amp;gt; overlays;

void free_surfaces()
{
for (unsigned int i = 0; i &amp;lt; elements.size(); i++)
{
delete elements;
}
elements.clear();
for (unsigned int i = 0; i &amp;lt; overlays.size(); i++)
{
delete overlays;
}
overlays.clear();
}

i am almost ready to make a demo app, i just need to finish this</description><link>http://forum.wiibrew.org/read.php?11,45886,45886#msg-45886</link><lastBuildDate>Tue, 16 Jun 2026 10:56:12 +0200</lastBuildDate>
<generator>Phorum 5.2.23</generator>
<item>
<guid>http://forum.wiibrew.org/read.php?11,45886,46031#msg-46031</guid>
<title>Re: correct way to delete?</title><link>http://forum.wiibrew.org/read.php?11,45886,46031#msg-46031</link><description><![CDATA[ If they&#039;re just pointers I assume you allocated, so deallocate using free(x), where x is a pointer to the region you&#039;d recently allocated.<br /><br />If your using C++, you can deallocate a region using the delete keyword, and allocate using the new keyword.<br />In C you allocate via malloc method, and deallocate via free.<br /><br />I&#039;m not sure how element::image is allocated, but it probably needs to be deallocated as well. It&#039;s possible the &#039;SDL&#039; header defines some method which deallocates an SDL_Surface.]]></description>
<dc:creator>JeremyWilms</dc:creator>
<category>Coding</category><pubDate>Tue, 05 Jan 2010 05:40:45 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,45886,45964#msg-45964</guid>
<title>Re: correct way to delete?</title><link>http://forum.wiibrew.org/read.php?11,45886,45964#msg-45964</link><description><![CDATA[ the vector is filled with push_back(), and the vector is just a list of pointers]]></description>
<dc:creator>SteelSLasher</dc:creator>
<category>Coding</category><pubDate>Mon, 04 Jan 2010 21:04:53 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,45886,45928#msg-45928</guid>
<title>Re: correct way to delete?</title><link>http://forum.wiibrew.org/read.php?11,45886,45928#msg-45928</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>Arikado</strong><br />If there&#039;s a destructor, you should call the destructor before deleteing them.</div></blockquote>Destructors are called by delete.<br /><br />How did you fill the vector? If you use malloc to create something and then delete to destroy it then things will go wrong.]]></description>
<dc:creator>Daid</dc:creator>
<category>Coding</category><pubDate>Mon, 04 Jan 2010 13:15:19 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,45886,45888#msg-45888</guid>
<title>Re: correct way to delete?</title><link>http://forum.wiibrew.org/read.php?11,45886,45888#msg-45888</link><description><![CDATA[ If there&#039;s a destructor, you should call the destructor before deleteing them.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Sun, 03 Jan 2010 20:18:30 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,45886,45886#msg-45886</guid>
<title>correct way to delete?</title><link>http://forum.wiibrew.org/read.php?11,45886,45886#msg-45886</link><description><![CDATA[ in my game engine the images to be drawn are stored in a vector similarly to libwiigui (most of my graphics coding is inspired by libwiigui) and i want to clear the vector of images, since the vector is a set of pointers i <i>thought</i> it would be correct to use delete but this seems to cause a hang in the code probably because i have kept to my php habits of being reckless<br /><br />i have put all the required info below including the structs for the variables in question:<br /><pre class="bbcode">
typedef struct <b>element</b>{
    SDL_Surface *image; //actual image for element
    int x; //x pos
    int y; //y pos
    int xvel; //velocity in x direction in pixels
    int yvel; //velocity in y direction in pixels
    int interval; //sets movements speed i.e setting to 50 would mean one movement per 50ms, allows slow movements
    SDL_Rect area; //part of image to display, default to entire image, allows tilesets for animating
};

vector&lt;<b>element</b>*&gt; <b>elements</b>;
vector&lt;<b>element</b>*&gt; <b>overlays</b>;

void free_surfaces()
{
    for (unsigned int i = 0; i &lt; <b>elements</b>.size(); i++)
    {
        delete <b>elements</b><i>;
    }
    <b>elements</b>.clear();
    for (unsigned int i = 0; i &lt; <b>overlays</b>.size(); i++)
    {
        delete <b>overlays</b><i>;
    }
    <b>overlays</b>.clear();
}
</i></i></pre><br />i am almost ready to make a demo app, i just need to finish this]]></description>
<dc:creator>SteelSLasher</dc:creator>
<category>Coding</category><pubDate>Sun, 03 Jan 2010 20:14:38 +0100</pubDate></item>
</channel>
</rss>