Hi Mike, You're right, it's a bug. I have just applied your proposed solution into SVN trunk, the corresponding ticket is #1531 (https://trac.pjsip.org/repos/ticket/1531). Thanks for such detail report. BR, nanang On Sat, May 26, 2012 at 9:35 PM, Michael Derfler <derfler.michael at gmail.com> wrote: > Hello, > I think I have found a problem with the new version of the media clock (used > by the master port) > > The problem: > > Part1: > * in pjmedia_clock_create2( ... ) a memory pool > ? ?is passed as an argument. > * from this pool's factory an other pool is created > ? (let's call it new_pool for now) > * from new_pool the memory for the pjmedia_clock "instance" > ? is "allocated" and a pointer to new_pool is stored to the instance. > > so far everything looks good. > Part2: > > in pjmedia_clock_start the clock thread is created from > new_pool (and started) > > > Part3: this is the point where the error occures > > in pjmedia_clock_stop the quitting flag is set to true > and the thread is joined. > > the problem: > ? ?* after joining pj_thread_destroy should be called to destroy the > thread's mutex. > ? ?* the memory allocated from new_pool is lost now because if you restart > the > ? ? ? clock (by calling pjmedia_clock_start) again new memory is "allocated" > from > ? ? ? new_pool --> new_pool is growing on each restart. > > If the MasterPort is enabled and disabled very often (don't know if this > happens that often) this behaviour can lead to > high memory consumption) > > possible solution: > > 1)in pjmedia_clock_create2 use the pool passed as an argument > ? ?to allocate memory for the pjmedia_clock instance > ? ?but also create new_pool and store the pointer (new_pool) to the > ? ?pjmedia_clock instance. > 2) in pjmedia_clock_start create the thread from new_pool > 3) in pjmedia_clock_stop: > ? ? ?join the thread (like it is done now) > ? ? ?but after that call pj_thread_destroy > ? ? ?and pj_pool_reset(new_pool) > > ? ? ?==> so the thread's mutex is destroyed + new_pool's memory usage is not > growing (when restarting) !!! > > I hope this was understandable. > If you have any questions, > I will try to answer them. > > mike > > > > > > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip at lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org >