[Mac] fix memory leaks

This commit is contained in:
YuLei 2012-09-04 02:06:04 +08:00
parent a25b1b3f2f
commit 09b0d9c843
3 changed files with 93 additions and 77 deletions

View File

@ -59,13 +59,10 @@ static id s_sharedDirectorCaller;
-(void) dealloc
{
s_sharedDirectorCaller = nil;
NSLog(@"~~ delete CCDirectorCaller");
NSLog(@"cocos2d: deallocing CCDirectorCaller %@", self);
if (displayLink) {
CVDisplayLinkRelease(displayLink);
}
if (renderTimer) {
[renderTimer release];
}
[super dealloc];
}

View File

@ -1,26 +1,26 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CC_EGLVIEW_MAC_H__
#define __CC_EGLVIEW_MAC_H__
@ -28,7 +28,8 @@ THE SOFTWARE.
#include "platform/CCCommon.h"
#include "platform/CCEGLViewProtocol.h"
namespace cocos2d {
NS_CC_BEGIN
class CCSet;
class CCTouch;
class CCSize;
@ -36,22 +37,25 @@ class CCSize;
class CC_DLL CCEGLView : public CCEGLViewProtocol
{
public:
CCEGLView();
virtual ~CCEGLView();
bool isOpenGLReady();
static CCEGLView* sharedOpenGLView(void);
static void purgeSharedOpenGLView(void);
virtual ~CCEGLView(void);
virtual bool isOpenGLReady(void);
virtual bool setContentScaleFactor(float contentScaleFactor);
void end();
void swapBuffers();
void setIMEKeyboardState(bool bOpen);
void setMultiTouchMask(bool mask);
static CCEGLView* sharedOpenGLView();
virtual void end();
virtual void swapBuffers(void);
virtual void setIMEKeyboardState(bool bOpen);
virtual void setMultiTouchMask(bool mask);
private:
static CCEGLView* s_sharedView;
CCEGLView(void);
};
} // end of namespace cocos2d
NS_CC_END // end of namespace cocos2d
#endif // end of __CC_EGLVIEW_MAC_H__

View File

@ -1,26 +1,26 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCEGLView.h"
#include "EAGLView.h"
#include "CCDirectorCaller.h"
@ -28,19 +28,40 @@ THE SOFTWARE.
#include "CCTouch.h"
#include "CCTouchDispatcher.h"
namespace cocos2d {
NS_CC_BEGIN
CCEGLView::CCEGLView()
CCEGLView* CCEGLView::s_sharedView = NULL;
CCEGLView* CCEGLView::sharedOpenGLView(void)
{
if (!s_sharedView)
{
s_sharedView = new CCEGLView();
}
return s_sharedView;
}
void CCEGLView::purgeSharedOpenGLView(void)
{
if (s_sharedView)
{
delete s_sharedView;
}
}
CCEGLView::CCEGLView(void)
{
m_obScreenSize.width = m_obDesignResolutionSize.width = [[EAGLView sharedEGLView] getWidth];
m_obScreenSize.height = m_obDesignResolutionSize.height = [[EAGLView sharedEGLView] getHeight];
}
CCEGLView::~CCEGLView()
CCEGLView::~CCEGLView(void)
{
CCLOG("cocos2d: deallocing CCEGLView %0x", this);
s_sharedView = NULL;
}
bool CCEGLView::isOpenGLReady()
bool CCEGLView::isOpenGLReady(void)
{
return [EAGLView sharedEGLView] != NULL;
}
@ -50,14 +71,14 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor)
return false;
}
void CCEGLView::end()
void CCEGLView::end(void)
{
[[CCDirectorCaller sharedDirectorCaller] end];
// destroy EAGLView
[[EAGLView sharedEGLView] removeFromSuperview];
// _exit(0);
purgeSharedOpenGLView();
}
void CCEGLView::swapBuffers()
@ -83,10 +104,4 @@ void CCEGLView::setMultiTouchMask(bool mask)
//glView.multipleTouchEnabled = mask ? YES : NO;
}
CCEGLView* CCEGLView::sharedOpenGLView()
{
static CCEGLView instance;
return &instance;
}
} // end of namespace cocos2d;
NS_CC_END // end of namespace cocos2d;