OS X: Create a help AutoreleasePool class

That wraps NSAutoreleasePool and releases it at destruction.

Change-Id: Ie7049450da46458f02c02d38439e20e43609ca83
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
Eike Ziller
2015-03-26 12:28:50 +01:00
parent 5183081c3a
commit 7a59dbc988
5 changed files with 60 additions and 27 deletions

View File

@@ -0,0 +1,51 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef AUTORELEASEPOOL_H
#define AUTORELEASEPOOL_H
#import <Foundation/NSAutoreleasePool.h>
namespace Utils {
class AutoreleasePool
{
public:
AutoreleasePool() { pool = [[NSAutoreleasePool alloc] init]; }
~AutoreleasePool() { [pool release]; }
private:
NSAutoreleasePool *pool;
};
} // Utils
#endif // AUTORELEASEPOOL_H

View File

@@ -28,9 +28,10 @@
** **
****************************************************************************/ ****************************************************************************/
#include "autoreleasepool.h"
#include <QUrl> #include <QUrl>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSURL.h> #include <Foundation/NSURL.h>
namespace Utils { namespace Utils {
@@ -38,12 +39,11 @@ namespace Internal {
QUrl filePathUrl(const QUrl &url) QUrl filePathUrl(const QUrl &url)
{ {
Utils::AutoreleasePool pool; Q_UNUSED(pool)
QUrl ret = url; QUrl ret = url;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *nsurl = url.toNSURL(); NSURL *nsurl = url.toNSURL();
if ([nsurl isFileReferenceURL]) if ([nsurl isFileReferenceURL])
ret = QUrl::fromNSURL([nsurl filePathURL]); ret = QUrl::fromNSURL([nsurl filePathURL]);
[pool release];
return ret; return ret;
} }

View File

@@ -198,6 +198,7 @@ FORMS += $$PWD/filewizardpage.ui \
RESOURCES += $$PWD/utils.qrc RESOURCES += $$PWD/utils.qrc
osx { osx {
HEADERS += $$PWD/autoreleasepool.h
OBJECTIVE_SOURCES += \ OBJECTIVE_SOURCES += \
$$PWD/fileutils_mac.mm $$PWD/fileutils_mac.mm
LIBS += -framework Foundation LIBS += -framework Foundation

View File

@@ -30,6 +30,7 @@
#include "spotlightlocatorfilter.h" #include "spotlightlocatorfilter.h"
#include <utils/autoreleasepool.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QMutex> #include <QMutex>
@@ -82,7 +83,7 @@ SpotlightIterator::SpotlightIterator(const QString &expression)
m_queueIndex(-1), m_queueIndex(-1),
m_finished(false) m_finished(false)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; Utils::AutoreleasePool pool; Q_UNUSED(pool)
NSPredicate *predicate = [NSPredicate predicateWithFormat:expression.toNSString()]; NSPredicate *predicate = [NSPredicate predicateWithFormat:expression.toNSString()];
m_query = [[NSMetadataQuery alloc] init]; m_query = [[NSMetadataQuery alloc] init];
m_query.predicate = predicate; m_query.predicate = predicate;
@@ -109,7 +110,6 @@ SpotlightIterator::SpotlightIterator(const QString &expression)
m_waitForItems.wakeAll(); m_waitForItems.wakeAll();
}] retain]; }] retain];
[m_query startQuery]; [m_query startQuery];
[pool release];
} }
SpotlightIterator::~SpotlightIterator() SpotlightIterator::~SpotlightIterator()
@@ -161,7 +161,7 @@ void SpotlightIterator::ensureNext()
return; return;
if (m_index >= 10000) // limit the amount of data that is passed on if (m_index >= 10000) // limit the amount of data that is passed on
return; return;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; Utils::AutoreleasePool pool; Q_UNUSED(pool)
// check if there are items in the queue, otherwise wait for some // check if there are items in the queue, otherwise wait for some
m_mutex.lock(); m_mutex.lock();
bool itemAvailable = (m_queueIndex + 1 < m_queue.count); bool itemAvailable = (m_queueIndex + 1 < m_queue.count);
@@ -177,7 +177,6 @@ void SpotlightIterator::ensureNext()
} }
m_mutex.unlock(); m_mutex.unlock();
[pool release];
} }
// #pragma mark -- SpotlightLocatorFilter // #pragma mark -- SpotlightLocatorFilter

View File

@@ -34,6 +34,7 @@
#include "openpagesmanager.h" #include "openpagesmanager.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/autoreleasepool.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QApplication> #include <QApplication>
@@ -68,26 +69,7 @@
#import <WebKit/WebUIDelegate.h> #import <WebKit/WebUIDelegate.h>
#import <WebKit/WebView.h> #import <WebKit/WebView.h>
// #pragma mark -- AutoreleasePool using namespace Utils;
class AutoreleasePool
{
public:
AutoreleasePool();
~AutoreleasePool();
private:
NSAutoreleasePool *pool;
};
AutoreleasePool::AutoreleasePool()
{
pool = [[NSAutoreleasePool alloc] init];
}
AutoreleasePool::~AutoreleasePool()
{
[pool release];
}
// #pragma mark -- mac helpers // #pragma mark -- mac helpers