- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个程序,可以使用强力回溯算法解决 C++ 中的数独谜题,但是在分析 valgrind 中的内存使用情况后,我注意到它有一个小泄漏。我知道一个 GCC 错误,它导致 1 个丢失的免费字节和 72,704 个字节仍然可以访问。
我似乎缺少 903 free()
/delete
/delete[]
调用,它们占用了大约 100KB 的内存。
有谁知道导致内存泄漏的原因以及如何修复它?
回溯器.cpp
#include "Backtracker.h"
/**
* Clears all dynamic memory in the list.
* @param lst: the pointer to the list to be cleared
*/
static void clearList(std::list<Grid*> *lst) {
std::list<Grid*>::iterator it;
for (unsigned int i = 0; i < lst->size(); i++) {
it = lst->begin();
std::advance(it, i);
delete *it;
}
delete lst;
}
/**
* Solves the sudoku puzzle or returns a null if there is no solution.
* @param g: a pointer to the starting grid
* @return: a pointer to the solution
*/
Grid* solve(Grid *g) {
if (g->isGoal()) {
return g;
}
std::list<Grid*> *successors = g->getSuccessors();
std::list<Grid*>::iterator it;
for (unsigned int i = 0; i < successors->size(); i++) {
it = successors->begin();
std::advance(it, i);
if ((*it)->isValid()) {
Grid *solution = solve(*it);
if (solution != nullptr) {
solution = solution->copyGrid();
clearList(successors);
return solution;
}
}
}
clearList(successors);
return nullptr;
}`
网格.cpp
#include "Grid.h"
/**
* Constructor for the Grid class.
*/
Grid::Grid() {
grid = new int*[SIZE];
for (int i = 0; i < SIZE; i++) {
grid[i] = new int[SIZE];
}
currRow = 0;
currCol = 0;
}
/**
* Destructor for the Grid class.
*/
Grid::~Grid() {
for (int i = 0; i < SIZE; i++) {
delete[] grid[i];
}
delete[] grid;
}
/**
* Getter for any value in the grid.
* @param row: the index of the row
* @param col: the index of the column
* @return: the value at the given row and column indexes
*/
int Grid::getValue(int row, int col) {
return grid[row][col];
}
/**
* Setter for any value in the grid.
* @param row: the index of the row
* @param col: the index of the column
* @param value: the value to set at the given row and column
*/
void Grid::setValue(int row, int col, int value) {
grid[row][col] = value;
}
/**
* Allocates dynamic memory for a new grid and copies over the contents.
* @return: a pointer to the new grid object
*/
Grid* Grid::copyGrid() {
Grid *copy = new Grid();
for (int r = 0; r < SIZE; r++) {
for (int c = 0; c < SIZE; c++) {
copy->setValue(r, c, grid[r][c]);
}
}
copy->currRow = currRow;
copy->currCol = currCol;
return copy;
}
/**
* Creates a list of successors by moving the cursor and setting the next value.
* @return: a list of the successors
*/
std::list<Grid*>* Grid::getSuccessors() {
std::list<Grid*> *successors = new std::list<Grid*>();
if (canMove()) {
Grid *copy = copyGrid();
copy->moveCursor();
if (copy->getValue(currRow, currCol) != 0) {
successors->push_back(copy);
return successors;
} else {
delete copy;
}
for (int i = 0; i < SIZE; i++) {
copy = copyGrid();
copy->moveCursor();
copy->setValue(currRow, currCol, i + 1);
if (copy->isValid()) {
successors->push_back(copy);
} else {
delete copy;
}
}
}
return successors;
}
/**
* Determines if the current configuration could be a possible solution.
* @return: true if it could be a solution, false if not
*/
bool Grid::isValid() {
// Checks each row for a duplicate number.
for (int r = 0; r < SIZE; r++) {
bool nums[SIZE] = {false * SIZE};
for (int c = 0; c < SIZE; c++) {
if ((grid[r][c] > 0) && (!nums[grid[r][c] - 1])) {
nums[grid[r][c] - 1] = true;
} else if ((grid[r][c] > 0) && (nums[grid[r][c] - 1])) {
return false;
}
}
}
// Checks each column for a duplicate number.
for (int c = 0; c < SIZE; c++) {
bool nums[SIZE] = {false * SIZE};
for (int r = 0; r < SIZE; r++) {
if ((grid[r][c] > 0) && (!nums[grid[r][c] - 1])) {
nums[grid[r][c] - 1] = true;
} else if ((grid[r][c] > 0) && (nums[grid[r][c] - 1])) {
return false;
}
}
}
// Checks squares.
int val;
for (int sRow = 0; sRow < SQUARES; sRow++) {
for (int sCol = 0; sCol < SQUARES; sCol++) {
bool nums[SIZE] = {false * SIZE};
for (int r = 0; r < SQUARES; r++) {
for (int c = 0; c < SQUARES; c++) {
val = grid[(sRow * 3) + r][(sCol * 3) + c];
if ((val > 0) && (!nums[val - 1])) {
nums[val - 1] = true;
} else if ((val > 0) && (nums[val - 1])) {
return false;
}
}
}
}
}
return true;
}
/**
* Determines if the current configuration is a solution or not.
* @return: true if it is a solution, false if not
*/
bool Grid::isGoal() {
for (int r = 0; r < SIZE; r++) {
for (int c = 0; c < SIZE; c++) {
if (grid[r][c] <= 0 || grid[r][c] > 9) {
return false;
}
}
}
return isValid();
}
/**
* Determines if the cursor can be advanced a position or not.
* @return: true if the cursor can be moved, false if it is at the last position of the board
*/
bool Grid::canMove() {
return !((currRow == SIZE - 1) && (currCol == SIZE));
}
/**
* Moves the cursor to the next position if it is not at the last position of the board.
* @return: true if the cursor was moved, false if it cannot be moved
*/
bool Grid::moveCursor() {
if (!canMove()) {
return false;
} else {
if (currCol != SIZE - 1) {
currCol++;
return true;
} else {
currCol = 0;
if (currRow == SIZE - 1) {
return false;
} else {
currRow++;
return true;
}
}
}
}
/**
* Creates a string for the given row.
* @param row: the index of the row to generate a string for
* @return: a string for that row
*/
std::string Grid::rowString(int row) {
std::string output = "";
int c;
for (c = 0; c < 3; c++) {
output += std::to_string(grid[row][c]) + " ";
}
output += "| ";
for (c = 3; c < 6; c++) {
output += std::to_string(getValue(row, c)) + " ";
}
output += "| ";
for (c = 6; c < SIZE; c++) {
output += std::to_string(getValue(row, c)) + " ";
}
return output;
}
/**
* Creates a string representation of the entire grid.
* @return: a string for the entire grid.
*/
std::string Grid::toString() {
std::string output = "";
// TODO remove this
output += std::to_string(currRow) + "," + std::to_string(currCol) + "\n";
int r;
for (r = 0; r < 3; r++) {
output += rowString(r) + "\n";
}
output += "---------------------\n";
for (r = 3; r < 6; r++) {
output += rowString(r) + "\n";
}
output += "---------------------\n";
for (r = 6; r < SIZE; r++) {
output += rowString(r) + "\n";
}
return output;
}`
valgrind 输出
==3021==
==3021== HEAP SUMMARY:
==3021== in use at exit: 106,488 bytes in 903 blocks
==3021== total heap usage: 3,260,824 allocs, 3,259,921 frees, 121,174,996 bytes allocated
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 19 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x401A69: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 20 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 21 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 22 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 23 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 24 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 25 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 26 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 27 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 412 (16 direct, 396 indirect) bytes in 1 blocks are definitely lost in loss record 28 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x40230F: main (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== 29,664 (1,152 direct, 28,512 indirect) bytes in 72 blocks are definitely lost in loss record 31 of 32
==3021== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3021== by 0x402620: Grid::copyGrid() (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x404104: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021== by 0x4040ED: solve(Grid*) (in /home/anthony/Documents/Code/c-c++-projects/Sudoku-Solver/sudoku-solver)
==3021==
==3021== LEAK SUMMARY:
==3021== definitely lost: 1,312 bytes in 82 blocks
==3021== indirectly lost: 32,472 bytes in 820 blocks
==3021== possibly lost: 0 bytes in 0 blocks
==3021== still reachable: 72,704 bytes in 1 blocks
==3021== suppressed: 0 bytes in 0 blocks
==3021== Reachable blocks (those to which a pointer was found) are not shown.
==3021== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3021==
==3021== For counts of detected and suppressed errors, rerun with: -v
==3021== ERROR SUMMARY: 11 errors from 11 contexts (suppressed: 0 from 0)
最佳答案
不确定这是你的问题,但是...根据 valgrind,问题与 Grid::copyGrid()
中分配的内存有关,因此由以下 分配的内存新的
Grid* Grid::copyGrid() {
Grid *copy = new Grid();
// ...
return copy;
}
我怀疑问题(一个问题?)在 solve()
中。
if ((*it)->isValid()) {
Grid *solution = solve(*it);
if (solution != nullptr) {
solution = solution->copyGrid();
clearList(successors);
return solution;
}
}
观察 solve()
返回一个 solution
是通过
solution = solution->copyGrid();
因此一个分配的(新
)值,但丢失了通过
solution
的原始值
Grid *solution = solve(*it);
来自solve()
所以它被分配了。
我的意思是:在哪里删除 solve()
返回的值?
我想你应该这样写
if ((*it)->isValid()) {
Grid *solution = solve(*it);
if (solution != nullptr) {
Grid *retSol = solution->copyGrid();
clearList(successors);
delete solution;
return retSol;
}
}
-- 编辑 --
OP 答案:
I just tried this, however it only causes a segmentation fault. Removing the delete solution; line fixes the segmentation fault, but the memory leak is still there.
我明白了...这里的问题是(如果我没记错的话)solve()
也可以返回接收到的值
Grid* solve(Grid *g) {
if (g->isGoal()) {
return g;
}
嗯……
因此,如果它不同于*it
,您必须仅删除它。
我不喜欢但我求婚
if ((*it)->isValid()) {
Grid *solution = solve(*it);
if (solution != nullptr) {
Grid *retSol = solution->copyGrid();
clearList(successors);
if ( solution != *it )
delete solution;
return retSol;
}
}
关于c++ - 找不到小内存泄漏的来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44998253/
IntentReceiver 正在泄漏 由于 onDetachedFromWindow 在某些情况下未被调用。 @Override protected void onDetachedFromWind
好吧,我很难追踪这个内存泄漏。运行此脚本时,我没有看到任何内存泄漏,但我的 objectalloc 正在攀升。 Instruments 指向 CGBitmapContextCreateImage >
我编写了一个测试代码来检查如何使用 Instrument(Leaks)。我创建了一个单一 View 应用程序,单击按钮后我加载了一个像这样的新 View ... - (IBAction)btn_clk
我正在使用这个简单的代码并观察单调增加的内存使用量。我正在使用这个小模块将内容转储到磁盘。我观察到它发生在 unicode 字符串上而不是整数上,我做错了什么吗? 当我这样做时: >>> from u
我有以下泄漏的代码。 Instruments 表示,泄漏的是 rssParser 对象。我“刷新”了 XML 提要,它运行了该 block 并且发生了泄漏...... 文件.h @interface
我在我编写的以下代码片段中发现了内存泄漏 NSFileManager *fileManager=[[NSFileManager alloc] init]; fileList=[[fileManager
因此,我正在开发HTML5 / javascript rts游戏。观察一直有几种声音在播放。因此,对我来说,是一段时间后声音听起来像是“崩溃”,并且此浏览器选项卡上的所有声音都停止了工作。我只能通过重
下面是我正在使用的一段代码及其输出。 my $handle; my $enterCount = Devel::Leak::NoteSV($handle); print "$date entry $en
在这篇关于 go-routines 泄漏的帖子之后,https://www.ardanlabs.com/blog/2018/11/goroutine-leaks-the-forgotten-sende
我想知道为什么在执行 ./a.out 后随机得到以下结果。有什么想法我做错了吗?谢谢 http://img710.imageshack.us/img710/8708/trasht.png 最佳答案 正
我正在 Swift 中开发一个应用程序,在呈现捕获我放在一起的二维码的自定义 ViewController 后,我注意到出现了巨大的内存跳跃。 该代码本质上基于以下示例:http://www.appc
下面是我的 javascript 代码片段。它没有按预期运行,请帮我解决这个问题。 function getCurrentLocation() { console.log("insi
我们在生产环境中部署了 3 个代理 Kafka 0.10.1.0。有些应用程序嵌入了 Kafka Producer,它们将应用程序日志发送到某个主题。该主题有 10 个分区,复制因子为 3。 我们观察
我正在使用仪器来检测一些泄漏,但有一些泄漏我无法解决; NSMutableString *textedetails = [[NSMutableString alloc] init];
如果我使用性能工具测试我的代码 - 泄漏,它没有检测到任何泄漏。这是否意味着代码没有泄漏任何内存? 我有一个越狱的 iPhone,我可以监控可用内存。如果有人知道,那就是 SBSettings。我测试
我在从 AddressBook 中获取图像时遇到了很大的问题,下面我粘贴了我的代码。此 imageData 从未被释放,在我的 Allocations Instruments 上它看起来总是在内存中它
- (NSMutableArray *)getArrayValue:(NSArray *)array{ NSMutableArray *valueArray = [NSMutableArra
Instruments 工具说这是一个泄漏,有什么想法吗? 我在 for 循环结束时释放变量对象 在上述方法的开头,这就是我设置变量对象的方式,即自动释放; NSMutableArray *varia
我正在跟踪我的 iOS 应用程序的内存泄漏,我有一个奇怪的泄漏导致我的应用程序崩溃......负责的框架是:CGImageMergeXMPPropsWhithLegacyProps。在某些时候,我的应
我正在尝试使用 NSOperationQueue 在后台线程中执行一个方法,如下所示: NSOperationQueue *queue = [NSOperationQueue new]; NS
我是一名优秀的程序员,十分优秀!