openframeworks / openframeworks/openFrameworks

Potential memory leak creating and closing additional windows

Open
#7,582 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

core
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

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();
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with featureOutputFS::openFS() and closeFS(), reproducing repeated creation and closing of the additional windows while monitoring memory. Check the window, listener, shared-context, and allWindows lifecycles shown in the issue; done means repeated open/close cycles no longer show unbounded memory growth and the existing draw listener behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.