openframeworks / openframeworks/openFrameworks
Potential memory leak creating and closing additional windows
Nobody has claimed this yet.
- 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.
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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