<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body>
Thanks, a little test program allocating a char buffer and deleting it afterwards
proved that. How can I keep track of the "used" memory in Unix (top obviously
does not show what I want to see...)?<br>
<br>
How are other processes affected by this behaviour of Unix? Say, I have a
program that allocates 1 GB of memory and deletes it right afterwards, then
it's for example waiting for user input. On a system with 0.5 GB of main
memory and 1 GB of swap space, can I do the following?:<br>
<br>
start program<br>
wait until it has freed its memory and waits for user input<br>
start the same program again (while the first process is still running)<br>
<br>
I guess the second process should crash since there is not enogh memory available
(main memory + swap = 1.5 GB, process1 + process2 = 2 GB, even though process1
already freed its memory). Is this correct? Can I do something against this?<br>
<br>
Thanks,<br>
<br>
Michael<br>
<br>
<br>
<br>
William A. Hoffman wrote:<br>
<blockquote type="cite"
 cite="mid6.1.1.1.2.20040818103610.053d6a40@pop.nycap.rr.com">
  <pre wrap="">Windows memory management is different than UNIX.
With Windows, the memory is returned to the OS after delete or free,
so programs like top show more memory.   With UNIX, the
memory is not returned to the OS, but is kept by the program until
exit.  The memory is still being free'ed and is available to the
running program.

-Bill


At 10:12 AM 8/18/2004, Michael wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi,

if I properly understand

<a class="moz-txt-link-freetext" href="http://public.kitware.com/pipermail/insight-users/2003-September/004820.html">http://public.kitware.com/pipermail/insight-users/2003-September/004820.html</a>

any memory referenced by smart pointers should be released when leaving the local scope in which the smart pointers were defined. I've written the following little program:

#include &lt;iostream&gt;
#include "itkImage.h"
#include "itkImageFileReader.h"

int main(int argc, char** argv)
{
  const unsigned int Dimension = 2;
  typedef unsigned char PixelType;
  typedef itk::Image&lt;PixelType, Dimension&gt; ImageType;
  typedef itk::ImageFileReader&lt;ImageType&gt; ReaderType;

  char ch;

  std::cout &lt;&lt; "before block" &lt;&lt; std::endl;
  std::cin &gt;&gt; ch;


  { // local scope

      ReaderType::Pointer reader = ReaderType::New();

      if (argc &lt; 2) {
          std::cout &lt;&lt; "filename required." &lt;&lt; std::endl;
          return -1;
      }
      reader-&gt;SetFileName(argv[1]);

      try {
          reader-&gt;Update();
      } catch (itk::ExceptionObject &amp;e) {
          std::cout &lt;&lt; e &lt;&lt; std::endl;
          return -1;
      }

      std::cout &lt;&lt; "after update: " &lt;&lt; std::endl;
      std::cin &gt;&gt; ch;
  }

  std::cout &lt;&lt; "after block" &lt;&lt; std::endl;
  std::cin &gt;&gt; ch;

  return 0;
}

When compiling it with Visual Studio 6 under Windows and looking at the memory usage at the points asking for input everything looks ok: The memory usage is about 1.5 MB before the local scope, about 7.8 MB after the update call and about 2.2 MB after leaving the local scope. Obviously, the image data has been released (I used the BrainProtonDensitySliceBorder20.png image, which I upscaled by a factor 10 (in each direction)). Except of the (small) difference of 0.7 MB the same amount of memory is used before and after the local scope (where do the 0.7 MB come from?).

When I compile the program with gcc under SunOS, however, the memory usage behaves differently. "top" shows the following values:

before block: SIZE 4888K, RES 1672K
after update: SIZE 10M, RES 8520K
after block: SIZE 10M, RES 8520K

It seems to me, that the memory of the smart pointers was not freed after leaving the local scope. Why is the behaviour different from the one in Windows?

Thanks,

Michael


_______________________________________________
Insight-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Insight-users@itk.org">Insight-users@itk.org</a>
<a class="moz-txt-link-freetext" href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a>
    </pre>
  </blockquote>
  <pre wrap=""><!---->
_______________________________________________
Insight-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Insight-users@itk.org">Insight-users@itk.org</a>
<a class="moz-txt-link-freetext" href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a>


  </pre>
</blockquote>
<br>
</body>
</html>