Threads & Memory

G

Guest

I create a method that copy files from one folder to another (see the ex.
code).
A new thread will create every time when user click the button.
The button is enable only when the copy process was finished( ThreadState =
Stop )

My question is when ThreadState = Stop, the system will release the Memory
or not?

Is my code generated multiply threads?

Thanks,


Code:

private Thread copyFiles;

private void btnImport_Click(object sender, System.EventArgs e)
{
copyFiles = new Thread( new ThreadStart(CopyFilesToProcessFolder) );
copyFiles.Start();
}
 
S

Stoitcho Goutsev \(100\)

ano,

What do you mean by releasing a memory.
The thread doesn't own any memory except that it has its own stack. The
memory is own by a process and threads are something like virtual CPUs
executing the code.
 
G

Guest

I mean a stack memory. Will it use the same stack or create create a new one
when the button is clicked? Will the threads throw their own stack when their
status is Stop?

Thanks,
 
S

Stoitcho Goutsev \(100\)

While there is a code executed by the thread it cannot throw its stack. Once
the thread procedure exits you the thread stack is empty and all local data
is gone anyway. When the thread is finalized all the resources it holds
(including the stack) are released.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top