openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

Potential memory leak creating and closing additional windows

Open dimitre opened this issue 11 months ago • 2 comments

I'm creating and closing windows by demand, maybe I'm doing something wrong, but it seems it is causing a memory leak. Should I take more steps to close properly? Edit: in the blue graph the only thing I'm doing is creating and closing a new window. I've also experimented with a blank new glfw simple window and it release the memory properly.

Screen Shot 2023-08-02 at 01 02 53

void featureOutputFS::openFS() {
	int monitorCount;
	GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
	cout << "openFS - Screens Found: " << monitorCount << " -- " << glfwGetVersionString() <<  endl;
	auto mainWindow = ofGetCurrentWindow();

	ofGLFWWindowSettings settings;
	settings.windowMode = OF_FULLSCREEN;
	settings.shareContextWith = mainWindow;

	string output;
	for (int a=0; a<monitorCount; a++) {
		const GLFWvidmode * desktopMode = glfwGetVideoMode(monitors[a]);
		glm::ivec2 size = glm::vec2(desktopMode->width, desktopMode->height);
		settings.setSize(size.x, size.y);
		glm::ivec2 pos;
		glfwGetMonitorPos(monitors[a], &pos.x, &pos.y);
		settings.setPosition(pos);

		output += "-	display # " + ofToString(a) + " : " + glfwGetMonitorName(monitors[a]) + "\n" +
		"	position: " + ofToString(pos.x) + " x " + ofToString(pos.y) +
		" -- " +
		"size: " + ofToString(size.x) + " x " + ofToString(size.y) +
		"\n";

		if (a > 0) {
			auto w = ofCreateWindow(settings);
			cout << "count! " << w.use_count() << endl;
			allWindows.emplace_back(w);
			cout << "count! " << w.use_count() << endl;
//			allWindows.emplace_back(ofCreateWindow(settings));
			ofAddListener(allWindows.back()->events().draw, this, &featureOutputFS::drawSecondWindow);
		}

	}
	cout << output << endl;
}


void featureOutputFS::closeFS() {
	cout << "featureOutputFS close " << glfwGetVersionString() << endl;
	fbo = soft->fboFinal;
	for (auto & a : allWindows) {
		ofRemoveListener(a->events().draw, this, &featureOutputFS::drawSecondWindow);
		a->setWindowShouldClose();
	}
	allWindows.clear();
}

dimitre avatar Aug 02 '23 04:08 dimitre