Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 4, 2008, 8:28:14 PM (16 years ago)
Author:
rgrieder
Message:

Completed destruction of static elements like XMLPort, Identifier, etc.
Of initially about 250 memory leaks (not in the actual meaning but the memory was never freed anyway) only 1 remains in TinyCpp.

  • Core class is now a normal Singleton that gets created and destroyed in main.
  • The same goes for Language, LuaBind, SignalHandler and PlayerManager.
  • Added a new std::set to the CommandExecutor so that the external ConsoleCommands can get destroyed too.
  • Code for destroying CommandLineArguments
  • Added destruction code for ConstructionCallbacks in Identifier
  • Moved internal identifier map (the one with the typeid(.) names) in a static function in Identifier. This was necessary in order to destroy ALL Identifiers with the static destruction function. Before it was possible to create an Identifier with having a class instance (that would call RegisterObject) for instance by simply accessing it via getIdentifier.
  • Removed a big memory leak in Button (forgot to destroy the ConfigValueContainers)
  • Added destruction code for InputBufferListenerTuples in InputBuffer destructor.
  • Added destruction code for load and save executors in both XMLPortParam and XMLPortObject
  • Added destruction code for ConsoleCommands in GSRoot, GSGraphics and GSLevel (temporary solution anyway)
  • Deleting the CEGUILua script module seems to work properly now, one memory leak less (GUIManager.cc)
  • Added global destruction calls in Main.cc
Location:
code/branches/objecthierarchy2/src/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/util/SignalHandler.cc

    r2171 r2344  
    3535#include "Debug.h"
    3636
    37 #include <cassert>
    3837#include <iostream>
    3938#include <cstdlib>
     
    4241namespace orxonox
    4342{
    44     SignalHandler * SignalHandler::singletonRef = NULL;
     43    SignalHandler* SignalHandler::singletonRef_s = NULL;
    4544}
    4645
     
    133132    void SignalHandler::sigHandler( int sig )
    134133    {
    135       for ( SignalCallbackList::iterator it = SignalHandler::getInstance()->callbackList.begin(); it != SignalHandler::getInstance()->callbackList.end(); it++  )
     134      for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++  )
    136135      {
    137136        (*(it->cb))( it->someData );
     
    184183      if ( sigPid == 0 )
    185184      {
    186         getInstance()->dontCatch();
     185        getInstance().dontCatch();
    187186        // wait for message from parent when it has attached gdb
    188187        int someData;
     
    237236
    238237      char cmd[256];
    239       snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance()->appName.c_str(), sigPid );
     238      snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid );
    240239      write( gdbIn[1], cmd, strlen(cmd) );
    241240
     
    331330      bt.insert(0, timeString);
    332331
    333       FILE * f = fopen( getInstance()->filename.c_str(), "a" );
     332      FILE * f = fopen( getInstance().filename.c_str(), "a" );
    334333
    335334      if ( !f )
    336335      {
    337         perror( ( std::string( "could not append to " ) + getInstance()->filename ).c_str() );
     336        perror( ( std::string( "could not append to " ) + getInstance().filename ).c_str() );
    338337        exit(EXIT_FAILURE);
    339338      }
     
    341340      if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
    342341      {
    343         COUT(0) << "could not write " << bt.length() << " byte to " << getInstance()->filename << std::endl;
     342        COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl;
    344343        exit(EXIT_FAILURE);
    345344      }
  • code/branches/objecthierarchy2/src/util/SignalHandler.h

    r2171 r2344  
    3737#include "UtilPrereqs.h"
    3838
     39#include <cassert>
    3940#include <list>
    4041#include <string>
     
    6869    class SignalHandler
    6970    {
    70     private:
    71         SignalHandler();
    7271    public:
    73         inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }
    74         ~SignalHandler(){ SignalHandler::singletonRef = NULL; }
     72        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
     73        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; }
     74        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
    7575
    7676        void registerCallback( SignalCallback cb, void * someData );
     
    8787        SignalCallbackList callbackList;
    8888
    89         static SignalHandler * singletonRef;
     89        static SignalHandler* singletonRef_s;
    9090
    9191        std::string appName;
     
    104104    {
    105105    public:
    106         inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; };
    107         void doCatch( const std::string & appName, const std::string & filename ) {};
    108         void dontCatch() {};
    109         void registerCallback( SignalCallback cb, void * someData ) {};
     106        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
     107        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; }
     108        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
     109        void doCatch( const std::string & appName, const std::string & filename ) {}
     110        void dontCatch() {}
     111        void registerCallback( SignalCallback cb, void * someData ) {}
    110112
    111113    private:
    112         static SignalHandler * singletonRef;
     114        static SignalHandler* singletonRef_s;
    113115    };
    114116}
Note: See TracChangeset for help on using the changeset viewer.