程序运行一段时间后,内存被耗尽了

长寿梦 2012-04-06 06:29:48
问题:程序运行一段时间后,内存被耗尽了
观察:通过系统自带的任务管理器观察进程的虚拟内存与线程数的变化:虚拟内存时而上升,
时而下降,但是下降的值小于上升的值导致内存在不断地耗掉;线程数,也在起伏变
化中 ;
程序可能逻辑:
为每一个新的会话对象创建线程专门处理该会话,当处理完毕时,销毁该线程;
问题跟踪:
通过vs2008的debug模式运行程序,启动测试环境,运行一段时间后,所观察现象还是如上
所观察的,但是当关闭程序时,vs2008自带的 C-runtime的内存泄露监测工具没有监测到
内存泄露的情况;
...全文
988 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
CandPointer 2012-05-22
  • 打赏
  • 举报
回复
有Intel 的强力的工具, 如果不差钱,那么,Visual Studio, 你只是把它当成 代码编辑器好了。

各种从编译到并行化,到检错,到高性能库,都是Intel 的

尤其是,检查 缓存命中率,数据竞争, Visual studio 根本不行。————微软的推销员最给力,把各种东西,推销给那么多用户

像pgi之类的编译器,都可以指定 目标代码运行的处理器的cache size。
至善者善之敌 2012-05-22
  • 打赏
  • 举报
回复
确信内存泄露?
CandPointer 2012-05-22
  • 打赏
  • 举报
回复
vs 自带的太不行了。


用 intel parallel studio 的 Inspector XE 绝对秒杀包括VS 2010 在内的 多种 checker


Intel® Inspector XE is a dynamic memory and threading error checking tool for users developing serial and multithreaded applications on Windows* and Linux* operating systems. You can also use the Intel Inspector XE to visualize and manage static security analysis results created by Intel® compilers in various suite products.

Intel Inspector XE currently supports applications:

Created with the C, C++, C++/CLI, C#, and Fortran programming languages

Developed in the Microsoft Visual Studio* 2005/2008/2010 IDE or other IDEs

Using the Intel® Threading Building Blocks, Intel® Cilk™ Plus, Windows* API, POSIX Threads API, and OpenMP* API programming models

Developed to run on the Windows* or Linux* operating systems listed in Release Notes.

*******************************
Parent topic: Intel® Inspector XE 2011
About Dynamic Analysis Problem Types

Cross-thread Stack Access
Occurs when a thread accesses a different thread's stack.
Data Race
Occurs when multiple threads access the same memory location without proper synchronization and at least one access is a write.
Deadlock
Occurs when two or more threads are waiting for each other to release resources (such as mutexes, critical sections, and thread handles) while holding resources the other threads are trying to acquire. If none of the threads release their resources, then none of the threads can proceed.
GDI Resource Leak
Occurs when a GDI object is created but never deleted.
Incorrect memcpy Call
Occurs when an application calls the memcpy function with two pointers that overlap within the range to be copied. This condition is only checked on Linux* systems. On Windows* systems, this function is safe for overlapping memory.
Invalid Deallocation
Occurs when an application calls a deallocation function with an address that does not correspond to dynamically allocated memory.
Invalid Memory Access
Occurs when a read or write instruction references memory that is logically or physically invalid.
Invalid Partial Memory Access
Occurs when a read or write instruction references a block (2-bytes or more) of memory where part of the block is logically invalid.
Kernel Resource Leak
Occurs when a kernel object handle is created but never closed.
Lock Hierarchy Violation
Occurs when the acquisition order of multiple synchronization objects (such as mutexes, critical sections, and thread handles) in one thread differs from the acquisition order in another thread, and these synchronization objects are owned by the acquiring thread and must be released by the same thread.
Memory Growth
Occurs when a block of memory is allocated but not deallocated within a specific time segment during application execution.
Memory Leak
Occurs when a block of memory is allocated and never released.
Mismatched Allocation/Deallocation
Occurs when a deallocation is attempted with a function that is not the logical reflection of the allocator used.
Missing Allocation
Occurs when an invalid pointer is passed to a deallocation function. The invalid address may point to a previously released heap block.
Thread Start Information
Occurs when the Intel Inspector XE detects the creation of a thread. This problem is really informational feedback useful for confirming the number and location of threads created during application execution and data collection.
Unhandled Application Exception
Occurs when the application undergoing analysis crashes because of an unhandled exception thrown by the application.
Uninitialized Memory Access
Occurs when a read of an uninitialized memory location is reported.
Uninitialized Partial Memory Access
Occurs when a read instruction references a block (2-bytes or more) of memory where part of the block is uninitialized.
Intel® Thread Checker Problem


********************************

Static security analysis can report over 250 different problem types that fall into the following broad categories:

Buffer overflows and boundary violations

Use of uninitialized variables and objects

Memory leaks

Incorrect usage of pointers and dynamically allocated memory

Dangerous use of unchecked input

Arithmetic overflow and divide by zero

Dead or redundant code

Misuse of string, memory, and formatting library routines

Inconsistent object declarations in different program units

Incorrect use of OpenMP* directives and Intel Cilk Plus language features

Error-prone C++ and Fortran language usage

赵4老师 2012-05-21
  • 打赏
  • 举报
回复
检查是否资源泄漏的办法之一:
在任务管理器 进程 查看 选择列 里面选择:内存使用、虚拟内存大小、句柄数、线程数、USER对象、GDI对象
让你的程序(进程)不退出,循环执行主流程很多遍,越多越好,比如1000000次甚至无限循环,记录以上各数值,再隔至少一小时,越长越好,比如一个月,再记录以上各数值。如果以上两组数值的差较大或随时间流逝不断增加,则铁定有对应资源的资源泄漏!
jiandingzhe 2012-05-21
  • 打赏
  • 举报
回复
内存泄漏?楼主试下valgrind,内存泄漏探测器,不过会大幅度降低运行速度。
W170532934 2012-05-10
  • 打赏
  • 举报
回复
关于资源的话尝试下用独享的指针来做呢??
godwind1123 2012-05-10
  • 打赏
  • 举报
回复
也有可能是这种情况 : 在两进程通信的过程中, A进程申请的内存交由B进程使用。通信成功时 最后这段内存交给B来注销。但是通信有可能不成功,那A进程中的错误处理往往就一个错误输出就return了,忘记了注销这段内存。
muyi66 2012-04-06
  • 打赏
  • 举报
回复
是否有反复往某个容器中加入数据而一直未作清理?包括STL容器和你自己定义的容器。
na_he 2012-04-06
  • 打赏
  • 举报
回复
用我说的那个重载new delete方法试一下,有其他分配的的函数可如法炮制。

3,882

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧