Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:35:19+00:00 2026-06-13T08:35:19+00:00

I am now searching for 2 weeks about this problem and seems that I

  • 0

I am now searching for 2 weeks about this problem and seems that I can’t find any answer just searching on the web.

So, here is two piece of code:

1:

#! /usr/bin/perl

#
# RELEASE MEMORY
#

use threads;

my @child;

$ii=0;


while (1)
{
  my @child = threads->new(\&test, "test");
  $_->detach for @child;
  print "$ii\n";
  $ii++;
}

sub test {
    my ($ee) = 0;    
}

2:

#! /usr/bin/perl

#
# DO NOT RELEASE MEMORY
#

use threads;

my @child;

$ii=0;


for($ii=0;$ii<2000;$ii++) {
    my @child = threads->new(\&test, "test");
    $_->detach for @child;
    print "$ii\n";
}

while(1)
{
  sleep(10);
}

sub test {
    my ($ee) = 0;    
}

So here’s the problem. The first code run only one infinite loop and it release memory back to operating system about each 2 seconds (according to ps)

The second code is releasing memory too but only when he’s running inside the “for” loop.
Once it exit the for loop and enter the infinite loop all the memory that have not been freed into the for loop is never released back to the operating system.

Is anybody experiencing the same issue ?

Perl: (v5.16.1) built for x86_64-linux-thread-multi

OS: Debian 6.0.5

Thanks a lot


Edit 1:
I used 800 threads and all verified that they exit by printing the $ee var.

But once entering the while(1) loop here’s the ps aux | grep perl output:

root@srv:~# ps aux | grep perl
root      6807 41.5  2.5 387780 209580 pts/0   S+   16:38   0:02 /opt/ActivePerl-5.16/bin/perl /home/tttlast.pl
root      7627  0.0  0.0   7548   856 pts/1    S+   16:38   0:00 grep perl

So all thread exited but the memory usage is still 2.5% of my server total memory.
So unless I kill the program the memory is still in use.


Edit 2:

I resolved my problem, I changed my structure. In fact the main program (the long running one) have been separated and I use small program who wait before all threads finish to exit.

This way It doesn’t full the virtual memory and other daemon are not killed.

Thanks to everyone leading me to that solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:35:21+00:00Added an answer on June 13, 2026 at 8:35 am

    There is no “issue” here. This is all normal, expected behavior. If this is causing you some kind of problem, you haven’t explained what it is.

    There’s no reason to return virtual memory to the operating system because virtual memory isn’t a scarce resource. There’s no reason to return physical memory to the operating system because the operating system will take it if it has a better use for it anyway.

    There’s no evidence it’s a memory leak. Test results suggest that there is no case where the memory usage increases without bound — in all cases it levels off eventually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm searching now for a while but can't find an entrance… The application should
I've been searching around now for quite a while and can't get any straight
Searching for a while now, but haven't found a suitable answer to my problem.
I've been searching for while now and I can't find a simple example of
I've been searching the web for a way to do this for about a
i've been searching and trying for weeks now to find a solution to my
I have been searching for an answer for this for almost a week now,
I remember reading something once, but could not find it now while searching, if
Ive tried searching for hours now and cannot find out why my code (aka,
I've been searching and experimenting for nearly four hours now, so I'm gonna just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.