<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Verdana">Hello, I've recompiled a Kylix app
into freepascal that uses threads and now with FPC I've noticed that
the memory used by my program is growing until it gets all of the
system memory.<br>
<br>
So I've made a simple app to test what was wrong, and this app shows
that the problem is with thread allocation. Each allocated thread is
getting more or less 2052 kb from memory and is never putting this back.<br>
<br>
The program I wrote to test is this that follows, it creates 10 threads
and then shows memory utilized ( by looking at file /proc/PID/status ),
then waits you to press enter, it will terminate all threads and show
the
memory again. When you press enter again it will alloc + 10 threads and
so on.<br>
<br>
I've seen on the bug-list of freepascal that anybody already registered
this as a bug, I want that somebody give me a direction for how to
begin to resolve this problem. I already browsed the on-line cvs and
looked at some of threads units on FPC source. But up to now I couldn't
find anything.<br>
<br>
Thanks for any help<br>
<br>
<br>
</font></font><big><big><font size="-1"><big><big><tt>program project1;<br>
<br>
{$mode objfpc}{$H+}<br>
<br>
uses<br>
cmem, cthreads, Libc, Classes, SysUtils<br>
{ add your units here };<br>
<br>
type<br>
TMyThread = class (TThread)<br>
private<br>
public<br>
procedure execute(); override;<br>
end;<br>
<br>
const MAXTHREADS = 9;<br>
<br>
var threads : array [0..MAXTHREADS] of TMyThread;<br>
i : integer;<br>
s : string;<br>
f : TextFile;<br>
pid : integer;<br>
<br>
procedure TMyThread.Execute();<br>
begin<br>
end;<br>
<br>
begin<br>
while (true) do<br>
begin<br>
for i := 0 to MAXTHREADS do<br>
begin<br>
threads[i] := TMyThread.Create(false);<br>
end;<br>
<br>
pid := getPid();<br>
AssignFile(f, '/proc/'+IntToStr(pid)+'/status');<br>
Reset(f);<br>
repeat<br>
ReadLn(f, s);<br>
until (Copy(s,1,6)='VmSize');<br>
Write(IntToStr(MAXTHREADS)+' threads initialized.....');<br>
WriteLn(s);<br>
<br>
ReadLn();<br>
<br>
for i := 0 to MAXTHREADS do<br>
begin<br>
threads[i].FreeOnTerminate := true;<br>
threads[i].Terminate;<br>
threads[i].Free;<br>
end;<br>
write('threads finalized.........');<br>
Reset(f);<br>
repeat<br>
ReadLn(f, s);<br>
until (Copy(s,1,6)='VmSize');<br>
writeln(s);<br>
writeln('');<br>
s := '';<br>
writeln('Press <ENTER> to try again');<br>
<br>
readln(s);<br>
if (s<>'') then break;<br>
end;<br>
<br>
end.<br>
<br>
</tt></big></big></font></big></big>
</body>
</html>
_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora!
http://br.acesso.yahoo.com