moreThanOneInstanceAllowed


#1

Since I don’t want multiple instances of my app, I’m returning false from moreThanOneInstanceAllowed. However, the second instance leaks memory.

I was able to get rid of most of them by changing part of JUCEApplication::enterMainApplicationLoop from this:

 if (! app->moreThanOneInstanceAllowed())
    {
        appLock = new InterProcessLock (T("juceAppLock_") + app->getApplicationName());

        if (! appLock->enter(0))
        {
            MessageManager::broadcastMessage (app->getApplicationName()
                                                + T("/") + *commandLine);

            delete appInstance;
            appInstance = 0;
            delete commandLine;

            return;
        }
    }[/code]

to this:

[code] if (! app->moreThanOneInstanceAllowed())
    {
        appLock = new InterProcessLock (T("juceAppLock_") + app->getApplicationName());

        if (! appLock->enter(0))
        {
            MessageManager::broadcastMessage (app->getApplicationName()
                                                + T("/") + *commandLine);

            delete appInstance;
            appInstance = 0;
            delete commandLine;

// ***************
// added these lines

            shutdownJuce_GUI();  
            delete appLock;          

// ***************

            return;
        }
    }

This took care of most of the leaks. However, I’m still leaking a Message object. As near as I can tell, it’s being generated by the idle timer for the message loop. I don’t see any obvious way to ensure that this gets cleaned up properly.

Any suggestions?

Thanks,

Matt


#2

I’d say don’t worry about it…

When the second intsance launches, it quits before any user code has been run, so there aren’t any user objects to worry about. And the few juce objects that get leaked aren’t important - not really worth the trouble of clearing them up when the app is about to terminate anyway.

Why is it causing you problems? Surely there’s not much point debugging a second instance of the app?


#3

I just don’t like leaking memory.

Before I made those changes, I was getting perhaps five or six leaks; now it’s just one.

If I duplicate what the library does (create my own InterProcessLock and use that to detect a second instance), the second instance of the application shuts down cleanly.

Matt


#4

I spend most of my time writing kernel code, so I tend to be compulsive about hunting down leaks. I suppose you can rely more on the OS to clean up in user mode.

Like you said, it’s not a big deal.

Matt


#5