GSdx: fixing the (texture) memory leak

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1464 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gabest11 2009-07-04 17:37:06 +00:00
parent 4c76909afe
commit 6eed14ae75
7 changed files with 19 additions and 30 deletions

View File

@ -34,6 +34,13 @@ GSDevice::GSDevice()
GSDevice::~GSDevice()
{
for_each(m_pool.begin(), m_pool.end(), delete_object());
delete m_backbuffer;
delete m_merge;
delete m_weavebob;
delete m_blend;
delete m_1x1;
}
bool GSDevice::Create(GSWnd* wnd, bool vsync)
@ -46,10 +53,7 @@ bool GSDevice::Create(GSWnd* wnd, bool vsync)
bool GSDevice::Reset(int w, int h, int mode)
{
for(list<GSTexture*>::iterator i = m_pool.begin(); i != m_pool.end(); i++)
{
delete *i;
}
for_each(m_pool.begin(), m_pool.end(), delete_object());
m_pool.clear();

View File

@ -66,10 +66,7 @@ public:
virtual ~GSFunctionMap()
{
for(hash_map<KEY, ActivePtr*>::iterator i = m_map_active.begin(); i != m_map_active.end(); i++)
{
delete i->second;
}
for_each(m_map_active.begin(), m_map_active.end(), delete_second());
}
VALUE operator [] (KEY key)
@ -177,10 +174,7 @@ public:
virtual ~GSCodeGeneratorFunctionMap()
{
for(hash_map<uint64, CG*>::iterator i = m_cgmap.begin(); i != m_cgmap.end(); i++)
{
delete i->second;
}
for_each(m_cgmap.begin(), m_cgmap.end(), delete_second());
}
VALUE GetDefaultFunction(KEY key)

View File

@ -883,10 +883,7 @@ GSRasterizerList::~GSRasterizerList()
void GSRasterizerList::FreeRasterizers()
{
for(list<IRasterizer*>::iterator i = begin(); i != end(); i++)
{
delete *i;
}
for_each(begin(), end(), delete_object());
clear();
}

View File

@ -87,8 +87,6 @@ GSState::GSState(uint8* base, bool mt, void (*irq)())
m_regs = (GSPrivRegSet*)(base + 0x12000000);
memset(m_regs, 0, sizeof(GSPrivRegSet));
PRIM = &m_env.PRIM;
// CSR->rREV = 0x20;
m_env.PRMODECONT.AC = 1;

View File

@ -38,10 +38,7 @@ void GSTextureCache::RemoveAll()
for(int type = 0; type < 2; type++)
{
for(list<Target*>::iterator i = m_dst[type].begin(); i != m_dst[type].end(); i++)
{
delete *i;
}
for_each(m_dst[type].begin(), m_dst[type].end(), delete_object());
m_dst[type].clear();
}
@ -842,10 +839,7 @@ void GSTextureCache::SourceMap::Add(Source* s, const GIFRegTEX0& TEX0, GSLocalMe
void GSTextureCache::SourceMap::RemoveAll()
{
for(hash_map<Source*, bool>::iterator i = m_surfaces.begin(); i != m_surfaces.end(); i++)
{
delete i->first;
}
for_each(m_surfaces.begin(), m_surfaces.end(), delete_first());
m_surfaces.clear();

View File

@ -130,10 +130,7 @@ const GSTextureCacheSW::GSTexture* GSTextureCacheSW::Lookup(const GIFRegTEX0& TE
void GSTextureCacheSW::RemoveAll()
{
for(hash_map<GSTexture*, bool>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
{
delete i->first;
}
for_each(m_textures.begin(), m_textures.end(), delete_first());
m_textures.clear();

View File

@ -53,12 +53,17 @@
#include <list>
#include <map>
#include <hash_map>
#include <algorithm>
using namespace std;
using namespace stdext;
extern string format(const char* fmt, ...);
struct delete_object {template<class T> void operator()(T& p) {delete p;}};
struct delete_first {template<class T> void operator()(T& p) {delete p.first;}};
struct delete_second {template<class T> void operator()(T& p) {delete p.second;}};
// syntactic sugar
// put these into vc9/common7/ide/usertype.dat to have them highlighted