0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ofxTweenzor を使用する際のメモリリーク対策

Last updated at Posted at 2018-07-18

#removeAllTweensではメモリを解放してくれない。
調子に乗ってaddしまくるとメモリリークを引き起こす危険があるので、Tweenzor.cpp内のremoveAll系の関数内で、vectorをswapしてメモリを解放する記述を足してやる。

##Tweenzor.cpp


void Tweenzor::removeAllTweens() {
	for(unsigned int i = 0; i < __instance->_events.size(); i++) {
		__instance->_events[i].destroy();
		__instance->_events[i] = NULL;
	}
	
	__instance->_events.clear();
	__instance->_tweens.clear();
    
    __instance->_tweens.swap(__instance->_tweens); //こいつを追加してvectorのメモリを解放
	
	cout << "Tweenzor :: removeAllTweens : " << __instance->_tweens.empty() << endl;
}

void Tweenzor::removeAllListeners() {
	__instance->_events.clear();
    
    __instance->_events.swap(__instance->_events); //こいつを追加してvectorのメモリを解放
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?