Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[03_answer] 提到的内存泄漏检测方法CRT为什么没有效果? #205

Open
wengjianhong opened this issue Nov 19, 2021 · 2 comments

Comments

@wengjianhong
Copy link

wengjianhong commented Nov 19, 2021

请问:在《第3节:解析字符串解答篇》的 1A. Windows 下的内存泄漏检测方法 中提到的 C Runtime Library(CRT) 检测内存泄漏
我在Windows10系统,VS2019下面运行一下代码,为什么没有提示内存泄露?

#include <iostream>
#define _WINDOWS
#ifdef _WINDOWS
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif

typedef struct Node
{
	int d[10];
}Node;

int main() {
#ifdef _WINDOWS
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	Node* node1 = new Node();
	Node* node2 = (Node*)malloc(sizeof(Node));
	std::cout << node1->d[0] << std::endl;
	std::cout << node2->d[0] << std::endl;
	_CrtDumpMemoryLeaks();
}

image

Linux环境下同样不行?
image

@wengjianhong wengjianhong changed the title [03_answer]: Windows 下的内存泄漏检测方法CRT [03_answer] 提到的内存泄漏检测方法CRT为什么没有提示内存泄露? Nov 19, 2021
@wengjianhong wengjianhong changed the title [03_answer] 提到的内存泄漏检测方法CRT为什么没有提示内存泄露? [03_answer] 提到的内存泄漏检测方法CRT为什么没有效果? Nov 19, 2021
@yqw123
Copy link

yqw123 commented Dec 2, 2021

我也是遇到了相同的情况,请问你现在有答案了吗?

@yqw123
Copy link

yqw123 commented Dec 3, 2021

有提示的,在输出那里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants