openFrameworks
openFrameworks copied to clipboard
Potential memory leak creating and closing additional windows
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();
}