Sign in to follow this  
arindampatra06

Memory Exception !!!!

Recommended Posts

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......

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this