Hi Victor,

I believe what you are seeing is a result of the implementation of the ILE
teraspace heap memory manager. At the point of the delete [] call, the
heap memory manager is not calling the operating system to actually free
the memory, but is instead adding the allocated memory to a reuse list. It
is doing this in anticipation that the memory will be reused at a later
point in the application. In general, this provides much better
performance than calling the operating system to allocate and free every
chunk of memory. The algorithm to determine how much memory is in the
reuse list is rather difficult to explain, but for the purposes of your
sample program, a maximum of ten allocations will be kept on the reuse
list. Once the reuse list is 'full' with the ten allocations, each delete
[] will call the operating system to actually free the memory. In all
cases, the memory will always be deallocated when the application ends.

There is no way to modify this behavior of the teraspace heap memory
manager. The specific reuse list algorithm can (and does) change slightly
from release to release.

FWIW, the _C_TS_malloc_info() function can be used to determine the exact
amount of teraspace heap memory allocated at any given point in time. This
may be of use to you in tracking down the memory leak. The documentation
for that function is available at
http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fctsmallocinfo.htm

Scott Hanson



From: Victor Gonzalez <victorpy@xxxxxxxxxxx>

To: <c400-l@xxxxxxxxxxxx>

Date: 05/18/2012 02:55 PM

Subject: [C400-L] memory deallocation with delete

Sent by: c400-l-bounces@xxxxxxxxxxxx







hello everyone,
Trying to debug a memory leak in a program, written in C++ and compiled
with ILE C++ compiler, i found an odd behavior with the temporary memory
allocation in the AS400.when i run the following piece of code:
int main(){
char *test;

sleep(10);

test = new char[20000000]; for(int i = 0; i < 20000000; i++)
{
test[i] = 'a'; }
sleep(10);
delete [] test; test = NULL; //q->PrintElements();
sleep(5);
}
i found that the temporary storage used is not released after the calling
"delete". The temporary storage used i use, is the one that could be seen
with the command DSPJOBD
In other test's if found that after allocating other kind of objects,
calling the delete operator immediately release the memory previously
allocated.
For compilation i use STDMDL *teraspace. The rest of the options are the
default
Any "enlightenment" about this behavior will be welcome
Thanks in advance.

--
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.



This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].