Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding in cocoainitializer class to prevent mem leaks on Cocoa-based Macs #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ qgit.pro.*
qgit.qbs.*
src/release
.qmake.stash
.DS_Store
src/qmake*
31 changes: 31 additions & 0 deletions src/cocoainitializer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2008 Remko Troncon
* Copyright (C) 2015 Ivan Romanov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#pragma once

class CocoaInitializer
{
public:
CocoaInitializer();
~CocoaInitializer();

private:
class Private;
Private *d;
};
42 changes: 42 additions & 0 deletions src/cocoainitializer.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2008 Remko Troncon
* Copyright (C) 2015 Ivan Romanov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>

#include "cocoainitializer.h"

class CocoaInitializer::Private
{
public:
NSAutoreleasePool *autoReleasePool_;
};

CocoaInitializer::CocoaInitializer()
{
d = new CocoaInitializer::Private();
NSApplicationLoad();
d->autoReleasePool_ = [[NSAutoreleasePool alloc] init];
}

CocoaInitializer::~CocoaInitializer()
{
[d->autoReleasePool_ release];
delete d;
}
3 changes: 2 additions & 1 deletion src/mainimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,8 @@ void MainImpl::ActAbout_activated() {
"<nobr>2018 <a href='mailto:[email protected]'>Mateusz Balbus</a>,</nobr> "
"<nobr>2019 <a href='mailto:[email protected]'>Sebastian Pipping</a>,</nobr> "
"<nobr>2019 <a href='mailto:[email protected]'>Matthias von Faber</a>,</nobr> "
"<nobr>2019 <a href='mailto:[email protected]'>Kevin Kofler</a></nobr> "
"<nobr>2019 <a href='mailto:[email protected]'>Kevin Kofler</a>,</nobr> "
"<nobr>2020 <a href='mailto:[email protected]'>Daniel Kettle</a></nobr> "

"</p>"

Expand Down
9 changes: 8 additions & 1 deletion src/qgit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
#pragma comment(linker,"/subsystem:windows")
#endif


#ifdef Q_OS_MAC
#include "cocoainitializer.h"
#endif

using namespace QGit;

int main(int argc, char* argv[]) {

#ifdef Q_OS_MAC
CocoaInitializer initializer;
#endif
QApplication app(argc, argv);
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
Expand Down
5 changes: 5 additions & 0 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ macx {
target.path = ~/bin
#CONFIG += x86 ppc
RC_FILE = resources/qgit.icns
# Import the CocoaInitializer class
QT += macextras # widgets-private gui-private core-private
LIBS += -framework Cocoa
OBJECTIVE_SOURCES += \
cocoainitializer.mm
}

HAVE_GCC {
Expand Down