Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Jun 2010 15:45:17 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Vikash Badal <Vikash.Badal@is.co.za>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: threads and malloc/free  on freebsd 8.0
Message-ID:  <20100611204517.GC36450@dan.emsphone.com>
In-Reply-To: <9B425C841283E0418B1825D40CBCFA613D9E3CA644@ZABRYSVISEXMBX1.af.didata.local>
References:  <9B425C841283E0418B1825D40CBCFA613D9E3CA643@ZABRYSVISEXMBX1.af.didata.local> <20100611195628.GB36450@dan.emsphone.com> <9B425C841283E0418B1825D40CBCFA613D9E3CA644@ZABRYSVISEXMBX1.af.didata.local>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jun 11), Vikash Badal said:
> > -----Original Message-----
> > From: owner-freebsd-questions@freebsd.org [mailto:owner-freebsd-
>  
> > The fix is to remove your second call to malloc_usable_size(z)).  Then
> > neither version will crash.  Also, a useful habit to start is to
> > explicitly zero the pointer you just free'd, to prevent it from being
> > used accidentally later.
> 
> Made this change:
> 
> <CODE>-----------
>    LogMessage(DEBUG_0, "allocated %ld", malloc_usable_size(inst));
>    
>    free(inst);
>    free(inst);
>    
>     return 0;
> -----------</CODE>
> 
> Still no seg fault.
> 
> The reason im am doing this is that from top I can see the memory grow as
> I connect to this app.  When I disconnect, the memory used ( as displayed
> from top ) does not decrease.

For performance reasons, the malloc library may not immediately release free
memory back to the OS.  Also, depending on the position of the memory block
being freed, it may not be releasable back to the OS (if malloc used sbrk
for allocations, it can only free memory at the far end of the address
space, for example).  Setting the environment variable MALLOC_OPTIONS to
"dM10f" might help (disable use of sbrk(), enable use of mmap(), don't cache
any free pages), but you still may not see any change according to top.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100611204517.GC36450>