I've been having memory leak issues with my application, and as it's in the physics module (which almost everything uses) it's causing a lot of slow down in the application. By using Visual Leak Detector i identified that the majority of the leaks were occurring due to the constructor, and the ApplyGravity function.
ParticleModel::ParticleModel(Transform* transform)
{
_transform = transform;
Acceleration = XMFLOAT3(0.0f, 0.0f, -0.1f);
mass = 10.0f;
force = XMFLOAT3(0.0f, 0.0f, 0.0f);
velocity = XMFLOAT3(0.0f, 0.0f, 0.0f);
netForce = XMFLOAT3(0.0f, 0.0f, 0.0f);
forceMag = 0.0f;
sForce = XMFLOAT3(0.0f, 0.0f, 0.0f);
dragFactor = 1.0f;
gravity = -9.81f;
_usingGravity = false;
_useConstAcc = true;
laminar = true;
radius = 0.5f;
CollisionCheck = false;
boolsForce = true;
move.x = 0.0f;
move.y = 0.0f;
move.z = 0.0f;
moveBy = 0.0f;
}
I commented out all of the variables aside from _transform = transform; and the memory leak from the constructor still occurred, also i side note is that i am freeing the memory of the pointer in the destructor of the class, although i'm not sure if this is the best place to be doing it.
ParticleModel::~ParticleModel()
{
delete _transform;
}
The second memory leak in ApplyGravity:
void ParticleModel::ApplyGravity()
{
_temp = XMFLOAT3(0.0f, gravity, 0.0f);
_forces.push_back(_temp); //_forces is a vector of XMFLOAT3s
}
I've played with Clearing the vector, but to no avail as the leak still occurs.
Output:
Leak Hash: 0x5522F309, Count: 1, Total 12 bytes
Call Stack (TID 1556):
MSVCR120D.dll!operator new()
c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 (848): DX11 Framework.exe!std::_Wrap_alloc<std::allocator<DirectX::XMFLOAT3> >::allocate()
c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector (1588): DX11 Framework.exe!std::vector<DirectX::XMFLOAT3,std::allocator<DirectX::XMFLOAT3> >::_Reallocate() + 0x17 bytes
c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector (1619): DX11 Framework.exe!std::vector<DirectX::XMFLOAT3,std::allocator<DirectX::XMFLOAT3> >::_Reserve()
c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector (1258): DX11 Framework.exe!std::vector<DirectX::XMFLOAT3,std::allocator<DirectX::XMFLOAT3> >::push_back()
particlemodel.cpp (58): DX11 Framework.exe!ParticleModel::ApplyGravity()
particlemodel.cpp (290): DX11 Framework.exe!ParticleModel::Update()
gameobject.cpp (27): DX11 Framework.exe!GameObject::Update() + 0x1F bytes
bbparticle.cpp (193): DX11 Framework.exe!BBParticle::Update()
smokeemitter.cpp (54): DX11 Framework.exe!SmokeEmitter::Update()
application.cpp (1254): DX11 Framework.exe!Application::Update() + 0x30 bytes
main.cpp (67): DX11 Framework.exe!wWinMain()
f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): DX11 Framework.exe!wWinMainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!RtlUnicodeStringToInteger() + 0x253 bytes
ntdll.dll!RtlUnicodeStringToInteger() + 0x21E bytes
Data:
00 00 00 00 C3 F5 1C 41 00 00 00 00 .......A ........
All the other leaks that are occurring i assume are due to ParticleModel being called in all the locations listed in the output. For instance ParticleModel::Update() calls ApplyGravity, and what not.