mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
Singleton CommandDirectory used to leak!
This commit is contained in:
parent
29349fedbb
commit
fd8fa69c62
@ -32,13 +32,10 @@
|
||||
#include "ImportExportCommands.h"
|
||||
#include "OpenSaveCommands.h"
|
||||
|
||||
CommandDirectory *CommandDirectory::mInstance = NULL;
|
||||
std::unique_ptr<CommandDirectory> CommandDirectory::mInstance;
|
||||
|
||||
CommandDirectory::CommandDirectory()
|
||||
{
|
||||
wxASSERT(mInstance == NULL);
|
||||
mInstance = this;
|
||||
|
||||
// Create the command map.
|
||||
// Adding an entry here is the easiest way to register a Command class.
|
||||
AddCommand(new ScreenshotCommandType());
|
||||
@ -96,17 +93,7 @@ void CommandDirectory::AddCommand(CommandType *type)
|
||||
|
||||
CommandDirectory *CommandDirectory::Get()
|
||||
{
|
||||
if (mInstance == NULL)
|
||||
{
|
||||
return new CommandDirectory();
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
void CommandDirectory::Destroy()
|
||||
{
|
||||
if (mInstance != NULL)
|
||||
{
|
||||
delete mInstance;
|
||||
}
|
||||
if (!mInstance)
|
||||
mInstance.reset(safenew CommandDirectory());
|
||||
return mInstance.get();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ they are kept separate to make things simpler.
|
||||
#ifndef __COMMANDDIRECTORY__
|
||||
#define __COMMANDDIRECTORY__
|
||||
|
||||
#include "../MemoryX.h"
|
||||
#include "CommandMisc.h"
|
||||
#include "CommandType.h"
|
||||
|
||||
@ -32,10 +33,9 @@ class CommandOutputTarget;
|
||||
class CommandDirectory
|
||||
{
|
||||
private:
|
||||
static CommandDirectory *mInstance;
|
||||
static std::unique_ptr<CommandDirectory> mInstance;
|
||||
CommandMap mCmdMap;
|
||||
public:
|
||||
CommandDirectory();
|
||||
~CommandDirectory();
|
||||
|
||||
/// If a command with the given name has been registered in the directory,
|
||||
@ -49,8 +49,8 @@ public:
|
||||
/// Get a pointer to the singleton instance
|
||||
static CommandDirectory *Get();
|
||||
|
||||
/// Manually DELETE the singleton instance
|
||||
static void Destroy();
|
||||
private:
|
||||
CommandDirectory();
|
||||
};
|
||||
|
||||
#endif /* End of include guard: __COMMANDDIRECTORY__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user