问题描述
- C++ ofstream close示范内存问题
-
准备用ofstream存取大量图片 存在txt中
发现内存一直在涨好像没有释放,直到崩溃。
代码如下//全局 ofstream file; while(true){ //调用摄像头blablabla //... //... //write 1000 images //输出图像地址 string name1 = "E:\workspace\data\imgs\"; string name3 = ".txt"; stringstream ss; string name2; ss<<counter; ss>>name2; string name = name1+name2+name3; //cvSaveImage(name.c_str(),); //write txt file.open(name); if(counter<1000){ if (!file) { cout << "can't open file"; cvWaitKey(100000); } for(int i=0;i<480;i++) { for(int j=0;j<640;j++) { unsigned char tmp = binaryData[i][j]; int tmpint = tmp; file<<tmpint<<" "; } } cout<<counter<<"img inputted !"; file.clear(); file.close(); } counter++; }
经过测试
注释掉下面语句就停止增长file<<tmpint<<" ";
貌似file.close 和file.clear都没起作用?
解决方案
可以下一个vld的库,看下是不是有内存泄露,不要好像没有释放
时间: 2024-08-03 11:06:04