免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1418 | 回复: 5
打印 上一主题 下一主题

在Shared Library里创建对象后将来释放时的疑虑 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-10-18 22:42 |只看该作者 |倒序浏览
请看另一个帖子《关于Shared Library在Solaris和HP-UX的不同结果》,假设在sl中(child对象)用new创建了另一些对象cobject,然后把这些cobject对象添加到一个list中,这个list是child的基类father中的成员。
某个时刻,我遍历这个father::list中的所有cobject对象,并用delete释放,这样的话,内存会有问题吗?有点担心,请高人指点。

论坛徽章:
0
2 [报告]
发表于 2005-10-18 23:18 |只看该作者

在Shared Library里创建对象后将来释放时的疑虑

没有问题.

论坛徽章:
0
3 [报告]
发表于 2005-10-18 23:37 |只看该作者

在Shared Library里创建对象后将来释放时的疑虑

能说一下你用虚基类的理由吗?

论坛徽章:
0
4 [报告]
发表于 2005-10-23 21:34 |只看该作者

在Shared Library里创建对象后将来释放时的疑虑

to Alligator27:
我想你也看了我另一篇帖子《关于Shared Library在Solaris和HP-UX的不同结果》,用purify联编其中的源代码后,检测日志如下,反映出有内存泄露的问题!!!

****  Purify instrumented ./test (pid 12204)  ****
Current file descriptors in use: 5
FIU: file descriptor 0: <stdin>;
FIU: file descriptor 1: <stdout>;
FIU: file descriptor 2: <stderr>;
FIU: file descriptor 26: <reserved for Purify internal use>;
FIU: file descriptor 27: <reserved for Purify internal use>;

****  Purify instrumented ./test (pid 12204)  ****
Purify: Searching for all memory leaks...

Memory leaked: 16 bytes (0.0784%); potentially leaked: 1232 bytes (6.03%)

MLK: 16 bytes leaked at 0x40052ac8
  * This memory was allocated from:
        malloc         [rtlib.o]
        __shlInit      [libCsup_v2.2]
        *unknown func* [pc=0xc87ec6a4]
        __shlinit      [libCsup_v2.2]
        form_load_graph#HLO_CL_#c10_0x0 [dld.sl]
        findlibsym#HLO_CL_#i2_0x3#I3_0x1#i4_0x0 [dld.sl]

PLK: 1168 bytes potentially leaked in 8 blocks
  * This memory was allocated from:
        malloc         [rtlib.o]
        __nW__fUl      [libCsup_v2.2]
        operator new(unsigned long) [rtlib.o]
        std::allocator<char>;::allocate(unsigned long,const void *) [memory]
        std::basic_string<char,std::char_traits<char>;,std::allocator<char>;>;::_C_getRep(unsigned long,unsigned long) [string.c
c]
        std::basic_string<char,std::char_traits<char>;,std::allocator<char>;>;::replace(unsigned long,unsigned long,const char *
,unsigned long,unsigned long,unsigned long) [string.cc]
  * Block of 146 bytes (8 times); last block at 0x40031f00

PLK: 32 bytes potentially leaked at 0x4002e890
  * This memory was allocated from:
        malloc         [rtlib.o]
        __nWa__FuL     [libCsup_v2.2]
        operator new[](unsigned long) [rtlib.o]
        static std::locale::_C_init() [libstd_v2.2]
        std::ios_base::Init::Init()%2 [libstd_v2.2]
        Static initializer (sinit) for "std::main_cpp_()" [main.o]

PLK: 32 bytes potentially leaked at 0x4002e908
  * This memory was allocated from:
        malloc         [rtlib.o]
        __nWa__FuL     [libCsup_v2.2]
        operator new[](unsigned long) [rtlib.o]
        static std::locale::_C_init() [libstd_v2.2]
        std::ios_base::Init::Init()%2 [libstd_v2.2]
        Static initializer (sinit) for "std::main_cpp_()" [main.o]

Purify Heap Analysis (combining suppressed and unsuppressed blocks)
                         Blocks        Bytes
              Leaked          1           16
  Potentially Leaked         11         1488
              In-Use         62        18911
  ----------------------------------------
     Total Allocated         74        20415

****  Purify instrumented ./test (pid 12204)  ****
Thread Summary : 1 threads in existence
  * Thread 0 [main thread]
     Stack Limit : (0x7f7f0c80 0x7fff0c80), size = 0x800000

论坛徽章:
0
5 [报告]
发表于 2005-10-23 21:37 |只看该作者

在Shared Library里创建对象后将来释放时的疑虑

mgb,dlopen - dlclose, Create() - Destroy(), new - delete,都配对了阿,那边会泄露呢?更别说在sl里面创建一些对象了,我想那样的话泄露更严重!

论坛徽章:
0
6 [报告]
发表于 2005-10-23 22:21 |只看该作者

在Shared Library里创建对象后将来释放时的疑虑

LZ应研究一下purify的文档资料. 上面贴的purify输出都是系统调用,STL run-time的泄露. 没有你的cobject.

purify报的这些泄露多办是误报. (PLK).
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP