Memory Exception !!!!

Started by
7 comments, last by alvaro 13 years, 4 months ago
As we are running the our game, at the time of loading the game , it is capturing 60% of the memory. but after that it still increasing the RAM memory.Even if we do not play the game after loading screen.
And the main problem i am getting, after 30min the RAM is getting overflown with 90% of its space and the game is crashing.

We are unable to understand the problem in our code.Even we have reduced the no. of textures, sound, polycounts.

We need your help......
Advertisement
Like the last time you are not supplying enough information. You are likely leaking memory somewhere. That's about as helpful as anyone can become.

Is everything that is newed later on deleted? Is the same true for new[] and delete[]? Are you calling Release() whenever required on your DirectX objects? Have you considered using smart pointers to reduce the risk of accidental leakage?
Fix your memory leaks.
Make sure that if yo uare doing any variable = new variable

are only happening within intilisation functions and that you are not creating new instances of objects everytime a frame is drawn etc.
Quote:Original post by eskimo456
Make sure that if yo uare doing any variable = new variable

are only happening within intilisation functions and that you are not creating new instances of objects everytime a frame is drawn etc.


Creating new objects via 'new'/'new[]' every frame is not the real cause of memory leaks. It is more about properly cleaning them up, either manually, or via smart pointers.

Or what exactly do you mean?
You can try out Visual Leak Detector with your project.
Try making this the first line in your main function:
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

and include crtdbg.h
#include <crtdbg.h>


Visual studio should report which memory has not yet been freed, and give you an allocation id.

You can then set a breakpoint on the allocation id.
I have the same problem in my project, when I generate lots of entities.

I don't think there is much to say:
- be careful to have a 'delete' for each 'new'
- be careful to have a 'delete[]' for each 'new[]'
- if you're using smart pointers, make certain that you don't use them in weird situations where they fail.

It should be easy for you to detect WHEN and WHERE you allocate memory. It has to be when you call 'new' (or some old style malloc).
Why do you think you need to use `new' to begin with? Or even pointers? I only ever need to use `new' for polymorphism, and then its use is restricted to a very clear place in the code (a factory function) and I use shared pointers to make sure the object is properly destroyed and its memory released when it's no longer needed.

I haven't had a memory leak in years.

This topic is closed to new replies.

Advertisement