<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Memory management in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460979#M680036</link>
    <description>Every malloc() call will allocate memory from process heap. You should call free() after you are done with the memory. You will see memory leak otherwise. You can confirm it with a tool like glance or ps.</description>
    <pubDate>Thu, 16 Jul 2009 08:16:22 GMT</pubDate>
    <dc:creator>Venkatesh BL</dc:creator>
    <dc:date>2009-07-16T08:16:22Z</dc:date>
    <item>
      <title>Memory management</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460978#M680035</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I have the following doubt about variables memory management in C.&lt;BR /&gt;&lt;BR /&gt;I have a function returning a pointer to "char":&lt;BR /&gt;&lt;BR /&gt;char *func(){&lt;BR /&gt; ....&lt;BR /&gt; char *x;&lt;BR /&gt; ....&lt;BR /&gt; x = malloc(20);&lt;BR /&gt; ....&lt;BR /&gt; return x;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;and then I use it in the following way:&lt;BR /&gt;&lt;BR /&gt;amb_buff = char[100];&lt;BR /&gt;...&lt;BR /&gt;for( ; ;)&lt;BR /&gt;{&lt;BR /&gt; ...&lt;BR /&gt; sprintf(amb_buff, "%s", func());&lt;BR /&gt; ...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;My question is about the memory allocated for "x" var by "malloc" in the routine:&lt;BR /&gt;&lt;BR /&gt;- is it freed after the "func" function return,&lt;BR /&gt;- or, at each iteration of the "for" cycle, a new 20 bytes of memory are added to the process memory amount?&lt;BR /&gt;&lt;BR /&gt;In few words: does the total process memory increase undefinitely?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Giuseppe Fedele&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jul 2009 08:01:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460978#M680035</guid>
      <dc:creator>Fedele Giuseppe</dc:creator>
      <dc:date>2009-07-16T08:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Memory management</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460979#M680036</link>
      <description>Every malloc() call will allocate memory from process heap. You should call free() after you are done with the memory. You will see memory leak otherwise. You can confirm it with a tool like glance or ps.</description>
      <pubDate>Thu, 16 Jul 2009 08:16:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460979#M680036</guid>
      <dc:creator>Venkatesh BL</dc:creator>
      <dc:date>2009-07-16T08:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Memory management</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460980#M680037</link>
      <description>Hi Giuseppe:&lt;BR /&gt;&lt;BR /&gt;To add, as noted already, calling 'malloc()' [or its cousins] allocates memory to the 'heap' (a program's memory pool) while 'free()' returns that memory to the heap.  This is designed for performance and is normal behavior.  That is, the freed memory is given to the program's heap but _not_ to the operating system at large until the program finally terminates.&lt;BR /&gt;&lt;BR /&gt;The heap can grow up to the size specified by 'maxdsiz' for 32-bit processes or up to 'maxdsiz_64bit' for 64-bit processes.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 16 Jul 2009 10:52:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460980#M680037</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-07-16T10:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Memory management</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460981#M680038</link>
      <description>If you compile this with aCC6's +wlint +O2 you get:&lt;BR /&gt;procedure func: warning #20200-D: Potential null pointer dereference through x is detected (null definition:itrc_leak.c, line 5)&lt;BR /&gt;procedure main: warning #20201-D: Memory leak is detected</description>
      <pubDate>Thu, 16 Jul 2009 11:01:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460981#M680038</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-16T11:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Memory management</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460982#M680039</link>
      <description>every malloc call should be freed when no longer needed. in this day and age, i don't use c anymore and moved on to some other languages (take a pick: python, java, etc.)&lt;BR /&gt;&lt;BR /&gt;they are not as slow as you might think and help to maintain your sanity and program stability!!</description>
      <pubDate>Mon, 20 Jul 2009 12:12:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-management/m-p/4460982#M680039</guid>
      <dc:creator>dirk dierickx</dc:creator>
      <dc:date>2009-07-20T12:12:17Z</dc:date>
    </item>
  </channel>
</rss>

