亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 4005 | 回復(fù): 10
打印 上一主題 下一主題

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2005-09-28 14:12 |只看該作者 |倒序?yàn)g覽
void testerr()
{
   std::vector<std::string>; vcon
   for(int i=0;i<1000000;++i)
     vcon.push_back("asdfasdfsd";
}

void testok()
{
  std::string ka="asdfasdfsd";
  std::vector<std::string>; vcon
  for(int i=0;i<1000000;++i)
    vcon.push_back(ka);
}
int main(int argc,char)
{
        testerr();//or testok
        getchar();
        return 123;
}

linux: redhat 8.0

can not see program release the memory.

but testok can release the memory.

note:use top tool to see the memory

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2005-09-28 14:49 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

應(yīng)該都沒有問題吧,按照C++的風(fēng)格,它應(yīng)該在析構(gòu)函數(shù)部分完成內(nèi)存釋放工作.
如果你不放心加一個 vcon.clear()

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2005-09-28 16:03 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

有沒有高人啊

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2005-09-28 17:04 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

問一下,怎么看出來release或者沒有release的。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2005-09-28 18:40 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

linux下可以用內(nèi)存泄漏用 valgrind 檢查。
你從TOP根本就看不出是否會產(chǎn)生內(nèi)存泄漏。

另外,上面的語句不會產(chǎn)生內(nèi)存泄漏,除非你中獎使用以前的某個版本的stl。

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2005-09-28 18:44 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

不懂啊,為何 testok 可以看到內(nèi)存使用下降,而testerr卻看不到呢?

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2005-09-28 18:48 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

系統(tǒng)有可能把已分配的內(nèi)存在進(jìn)程退出后作為系統(tǒng)緩存區(qū)使用。

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2005-09-28 20:09 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

stl是C++的標(biāo)準(zhǔn),只要是標(biāo)準(zhǔn)就應(yīng)該沒有問題!但按標(biāo)準(zhǔn)實(shí)現(xiàn)的程序就不一定了!!!

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2005-09-29 12:28 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

沒有令人滿意的回答

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2005-09-29 13:57 |只看該作者

stl 有內(nèi)存泄漏嗎?(高人指點(diǎn)一下)

不知道你的產(chǎn)生內(nèi)存泄漏的結(jié)論是如何的出來的.能不能給提供個數(shù)據(jù)看一下.


下面使用valgrind檢測的結(jié)果:

  1. [root@localhost prog]# valgrind -v memoryLeak
  2. ==2776== Memcheck, a memory error detector.
  3. ==2776== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
  4. ==2776== Using LibVEX rev 1313, a library for dynamic binary translation.
  5. ==2776== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
  6. ==2776== Using valgrind-3.0.0, a dynamic binary instrumentation framework.
  7. ==2776== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
  8. --2776-- Valgrind library directory: /usr/lib/valgrind
  9. --2776-- Command line
  10. --2776--    memoryLeak
  11. --2776-- Startup, with flags:
  12. --2776--    -v
  13. --2776-- Contents of /proc/version:
  14. --2776--   Linux version 2.6.13-1.1535_FC5 (bhcompile@bugs.build.redhat.com) (gcc version 4.0.1 20050831 (Red Hat 4.0.1-12)) #1 Sun Sep 4 02:20:28 EDT 2005
  15. --2776-- Reading syms from /root/prog/memoryLeak (0x8048000)
  16. --2776-- Reading syms from /lib/ld-2.3.90.so (0x1B8E4000)
  17. --2776-- Reading syms from /usr/lib/valgrind/stage2 (0xB0000000)
  18. --2776-- Reading suppressions file: /usr/lib/valgrind/default.supp
  19. ==2776==
  20. --2776-- Reading syms from /usr/lib/valgrind/vg_preload_core.so (0x1B8FF000)
  21. --2776-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck.so (0x1B902000)
  22. --2776-- REDIR: 0x1B8F8DB0 (index) redirected to 0x1B905084 (index)
  23. --2776-- Reading syms from /lib/libsafe.so.2.0.16c (0x1B908000)
  24. --2776--    object doesn't have a symbol table
  25. --2776-- Reading syms from /usr/lib/libstdc++.so.6.0.6 (0x1B934000)
  26. --2776--    object doesn't have a symbol table
  27. --2776-- Reading syms from /lib/libm-2.3.90.so (0x1BA1D000)
  28. --2776-- Reading syms from /lib/libgcc_s-4.0.1-20050831.so.1 (0x1BA42000)
  29. --2776--    object doesn't have a symbol table
  30. --2776-- Reading syms from /lib/libc-2.3.90.so (0x1BA4C000)
  31. --2776-- Reading syms from /lib/libdl-2.3.90.so (0x1BB78000)
  32. --2776-- REDIR: 0x1BAB6D60 (rindex) redirected to 0x1B904F94 (rindex)
  33. --2776-- REDIR: 0x1B8E47F0 (_dl_sysinfo_int80) redirected to 0xB0022B03 (???)
  34. --2776-- REDIR: 0x1BAB1BFE (malloc) redirected to 0x1B903793 (malloc)
  35. --2776-- REDIR: 0x1BAAFDC8 (free) redirected to 0x1B9042B2 (free)
  36. --2776-- REDIR: 0x1BAB7BD0 (memset) redirected to 0x1B9053D8 (memset)
  37. --2776-- REDIR: 0x1B9E8890 (operator new(unsigned)) redirected to 0x1B903B2E (operator new(unsigned))
  38. --2776-- REDIR: 0x1BAB8030 (memcpy) redirected to 0x1B905490 (memcpy)
  39. --2776-- REDIR: 0x1B9E7308 (operator delete(void*)) redirected to 0x1B904546 (operator delete(void*))
  40. ==2776==
  41. ==2776== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 26 from 2)
  42. --2776--
  43. --2776-- supp:    3 index-not-intercepted-early-enough-HACK-1
  44. --2776-- supp:   23 dl_relocate_object
  45. ==2776== malloc/free: in use at exit: 40417236 bytes in 9920 blocks.
  46. ==2776== malloc/free: 9951 allocs, 31 frees, 57194292 bytes allocated.
  47. ==2776==
  48. ==2776== searching for pointers to 9920 not-freed blocks.
  49. ==2776== checked 40536016 bytes.
  50. ==2776==
  51. ==2776== LEAK SUMMARY:
  52. [color=red]==2776==    definitely lost: 0 bytes in 0 blocks.
  53. ==2776==      possibly lost: 0 bytes in 0 blocks.
  54. ==2776==    still reachable: 40417236 bytes in 9920 blocks.
  55. ==2776==         suppressed: 0 bytes in 0 blocks.
  56. ==2776== Reachable blocks (those to which a pointer was found) are not shown.[/color]
  57. ==2776== To see them, rerun with: --show-reachable=yes
  58. --2776--  memcheck: sanity checks: 5229 cheap, 210 expensive
  59. --2776--  memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
  60. --2776--  memcheck: auxmaps: 0 searches, 0 comparisons
  61. --2776--  memcheck: secondaries: 765 issued (48960k, 47M)
  62. --2776--  memcheck: secondaries: 33 accessible and distinguished (2112k, 2M)
  63. --2776--     tt/tc: 5649 tt lookups requiring 5788 probes
  64. --2776--     tt/tc: 5649 fast-cache updates, 3 flushes
  65. --2776-- translate: new        2706 (60927 ->; 991661; ratio 162:10) [0 scs]
  66. --2776-- translate: dumped     0 (0 ->; ??)
  67. --2776-- translate: discarded  2 (95 ->; ??)
  68. --2776-- scheduler: 261466397 jumps (bb entries).
  69. --2776-- scheduler: 5229/18233 major/minor sched events.
  70. --2776--    sanity: 5230 cheap, 210 expensive checks.
  71. --2776--    exectx: 4999 lists, 26 contexts (avg 0 per list)
  72. --2776--    exectx: 10008 searches, 9982 full compares (997 per 1000)
  73. --2776--    exectx: 0 cmp2, 81 cmp4, 0 cmpAll
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP