Sign in to follow this  

Unity getting MMGR to ignore std::list

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently posted about a memory leak that was detected by MMGR, that was the result of std::list usage of a memory pool. So knowing that this wasn't really a memory leak, someone (i think it was Sneftel, thanks!) pointed out that I should just include nommgr.h before my standard includes, and mmgr.h afterwards. Well, that seemed simple enough, however I seem to still get the std::list "leak" reported by mmgr. So my question is: what is the proper way to integrate mmgr into a project. Before you say "RTFM", I would like to add that I did Read The Finger-licking-good Manual, but I am still having troubles. I understand that I should order my includes as follows: standard includes mmgr.h project includes There are a few questions about this though. Does this require me to have all of my includes in the .h files? Sometimes I throw an include in the .cpp when the .cpp is using something that is internal to that class, and doesn't need to be accessible to other classes that includes this file. Or should I have an "engine.h" like what is found in the Enginuity series here on gamedev, and include mmgr.h in that file? I have included a small working example of a possible use of mmgr, but this mmgr will report a leak allocated by "??(00000)::??". If i put a break point in the mmgr's new operator overload, I find that this is allocation originates from std::list. See for yourself: "header1.h"
#ifndef HEADER1_TEST_H__
#define HEADER1_TEST_H__

#include "nommgr.h"
#include <iostream>
#include <list>
#include "mmgr.h"

class Foo
{
private:
    std::list<std::string> stringList;
public:
    Foo() {}
    ~Foo() {}

};

#endif


"main.cpp"
#include "header1.h"

int main(void)
{
    Foo* foo = new Foo();

    return 0;
}


I would appreciate any helpful feedback on this matter. Thanks. [EDIT] To clarify, I know why mmgr thinks this is a memory leak (see link) But I would like to know how I can organize my project so that mmgr does not report this as a leak.

Share this post


Link to post
Share on other sites
It's reporting it as a memory leak because that's what your program does: leak memory. Your objects destructor is never called so I'm pretty sure the std::list destructor is never called, hence it will leak memory. Does it still report it if you put a delete foo; in there?

Share this post


Link to post
Share on other sites
Well, this was a small isolated example that I was hoping to use that would illustrate what I am seeing in my larger project. I know that in this exampale, "Foo* foo = new Foo()" is a leak, but it shouldn't be reporting foo's list as a leak, since I am trying to get mmgr to ignore stl.

EDIT:
So in this example mmgr reports 2 leakes, 1 in main and one in std::list. I would like it to only report 1 leak.

In the meantime, I will try to come up with a better example, where I delete foo but the std::list is still reported as a leak (this is what I am seeing in my larger project).

Share this post


Link to post
Share on other sites
One idea for why it might not be working(and I could be way off) is because since list, and most other STL classes are templates, most of their functions get inlined. It would seem that this could mean that the constructor is being inlined into main, which is being effected by the memory manager.

This is probably not right tho, as I'd think that the memory manager preprocessor replacements for new/delete would be done before any inlining, so that even inlined news from the list header would be the normal new, and not the memory manager new.

Share this post


Link to post
Share on other sites
Ah ha!!

EDIT
Don't be intimidated by all of the source blocks. This code is ridiculously simple and small.
END EDIT

Here is exactly my problem that I am seeing in my large project, the Foos are properly deleted, but the lists are still reported as leaks.

"main.cpp"

#include "header1.h"

int main(void)
{
Foo* foo = new Foo();
Foo* foo2 = new Foo();
Foo* foo3 = new Foo();

foo2->addChild(foo3);
foo->addChild(foo2);

foo->destroy();
delete foo;

return 0;
}




"header1.h"

#ifndef HEADER1_TEST_H__
#define HEADER1_TEST_H__

#include "nommgr.h"
#include <iostream>
#include <list>
#include "mmgr.h"

#include "header2.h"

class Foo : public CObject
{
private:
std::list<std::string> stringList;
public:
Foo() {}
~Foo() {}

};

#endif




"header2.h"

#ifndef HEADER2_H__
#define HEADER2_H__

#include "nommgr.h"
#include <list>
#include "mmgr.h"

class CObject
{
private:
std::list<CObject*> children;
public:
CObject() {}
~CObject() {}

virtual void destroy();
virtual void addChild(CObject* child);
};

#endif




"source2.cpp"

#include "header2.h"

void CObject::destroy()
{
for(std::list<CObject*>::iterator it=children.begin(),end=children.end();
it != end; it++)
{
(*it)->destroy();
delete *it;
}
}

void CObject::addChild(CObject* child)
{
children.push_back(child);
}




MMGR's output:

----------------------------------------------------------------------------------------------------------------------------------
| Memory leak report for: 01/26/2006 11:29:36 |
----------------------------------------------------------------------------------------------------------------------------------


2 memory leaks found:

Alloc. Addr Size Addr Size BreakOn BreakOn
Number Reported Reported Actual Actual Unused Method Dealloc Realloc Allocated by
------ ---------- ---------- ---------- ---------- ---------- -------- ------- ------- ---------------------------------------------------
000006 0x0032B8C0 0x00000024 0x0032B8B0 0x00000044 0x0000001C new N N ??(00000)::??
000009 0x0032BA20 0x00000024 0x0032BA10 0x00000044 0x0000001C new N N ??(00000)::??





Again, is there any way to prevent mmgr from reporting false leaks in std::list?

Share this post


Link to post
Share on other sites
And the leaks are because you invoked delete on a base class pointer to a derived class object where the base class destructor is not virtual. Make the CObject destructor virtual and everything will work fine. You are leaking memory currently (actually, it's worse than that. I'm pretty sure you have undefined behaviour, but don't have easy access to the final draft standard to check).

Enigma

Share this post


Link to post
Share on other sites
Enigma, you hit the nail on the head! I thought that the other list was leaking, due to memory pool allocation. Making CObjects destructor virtual fixed this whole mess. I can't believe I missed that. Well, big thanks to Enigma and big thanks to Paul Nettle for making a solid memory manager that can catch mistakes like this.

Problem solved. Thank you.

Share this post


Link to post
Share on other sites

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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  

  • Forum Statistics

    • Total Topics
      628706
    • Total Posts
      2984309
  • Similar Content

    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064

      View full story
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064
    • By Dafu
      Hello all,
      I've been hard at work on a new retro pixel-perfect framework called FES Retro Game Framework. It is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      My own game I started working on using FES, a roguelike, very early: https://simmer.io/@Dafu/merl
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064
       
       
    • By Apollo Cabrera
      Yasss!!! My first Unity3d game is on the App Store and Google Play.
      Download please! About 30 minutes to get through 5 missions.
      Let me know what you guys think.
      Thanks a bunch
       
    • By Mert Oguz
      well, i have started developing games last year, alone , I made a singleplayer 3d openworld rpg on unity you can look at it on googleplaystore ( kooru stone rpg ) whatever, this year, i wanted to make mmo, which gone really fine until I first try real hosting, I was working on "wamp" until then. The reason i am desperate now is that the way my game works.
      On my pc, using wamp mysql , with localhost as host for my game, i was testing my mmorpg with using andorid emulators, ofcourse no lag no issues no restrictions, beautiful dream... But then, I wanted to get real host from web, so, I rent a basic, cheaphest ever web host ( 10$ year ), and transferred my php files along with sql database. 
      So, I launched the game, still no issues, tried to handle 2-3 players by using my pc, phone, friend's phone...  
      After a while, ( after really short time (3-4mins)) host started not to respond, beacause those web hosting were not fit to handle mmos, i predicted that.
      now what i am explaining is that my game works like this and asking what way should i use to handle it :
      - Creates web request ( like : webhost.com/game/getplayerdata.php?ID=2 )
      -Reads request ( request result be like = "ID2-GoodGuyXx-23-123-4-123-43 )
      -Builds player using result string
      -does similar requests REEAALY FREQUENTLY  ( total requests of 8 - 12 times per seconds )
      With my current ultimate cheap web hosting, i can handle 2 players with low lag ( lol ) but, i want to handle around 20-100 players,
      just need a clear path, i have been struggling with google cloud sql and other vps server dedicated server options, i dont wanna pay much and get ripped off.
  • Popular Now