From: Yusuke ENDOH Date: 2010-07-15T22:16:12+09:00 Subject: [ruby-core:31299] Re: [Bug #3566] memory leak when spawning+joining Threads in a loop Hi, 2010/7/14 Eric Wong : > The following loop causes Ruby 1.9.2-rc2 memory usage to grow without bounds: > > �loop { Thread.new {}.join } I think the following patch fixes this issue. Even with the patch applied, memory usage seems to grow slowly. But it will stop eventually, as long as I investigated. I guess it is due to conservative GC. diff --git a/thread_pthread.c b/thread_pthread.c index e974b73..4db1226 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -213,22 +213,18 @@ get_stack(void **addr, size_t *size) CHECK_ERR(pthread_attr_getstackaddr(&attr, addr)); CHECK_ERR(pthread_attr_getstacksize(&attr, size)); # endif - if (pthread_attr_getguardsize(&attr, &guard) == 0) { - STACK_GROW_DIR_DETECTION; - STACK_DIR_UPPER((void)0, (void)(*addr = (char *)*addr + guard)); - *size -= guard; - } # else CHECK_ERR(pthread_attr_init(&attr)); CHECK_ERR(pthread_attr_get_np(pthread_self(), &attr)); CHECK_ERR(pthread_attr_getstackaddr(&attr, addr)); CHECK_ERR(pthread_attr_getstacksize(&attr, size)); # endif - CHECK_ERR(pthread_attr_getguardsize(&attr, &guard)); - *size -= guard; -# ifndef HAVE_PTHREAD_GETATTR_NP + if (pthread_attr_getguardsize(&attr, &guard) == 0) { + STACK_GROW_DIR_DETECTION; + STACK_DIR_UPPER((void)0, (void)(*addr = (char *)*addr + guard)); + *size -= guard; + } pthread_attr_destroy(&attr); -# endif #elif defined HAVE_PTHREAD_GET_STACKADDR_NP && defined HAVE_PTHREAD_GET_STACKSIZE_NP pthread_t th = pthread_self(); *addr = pthread_get_stackaddr_np(th); -- Yusuke Endoh