|
Hi Christian,
Could you please have a look at my reply to CaiX message. No I am not using ZX81, however the client is using Citrix with some 150 user base so memory usage does impact server utilisation.
Also, how a form is shown does impact.
ShowDialog() does GC the form. (and only the internal Finalize() method calls Dispose as Dispose(false)
whereas
Show() automatically calls Dispose(true) on Close and never GC's the form.
|
|
|
|
|
OK, sounds like you're learning a lot about how the GC works. So, make your forms member variables, which is the only half reasonable way to create forms you call Show on, anyhow. Then, recycle the same form, instead of creating them all the time.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for your help.
I believe I've sorted the problem.
If I minimize and maximize the main mdi form the Task Manager reports a low resized memory. So the GC really only works when it needs too and if there is no memory pressure it just lets the app grow. Thanks.
|
|
|
|
|
For most variables if you declare them in a function:
private void DoSomething()
{
MyClass yada;
yada = new MyClass();
}
Then yada gets garbage collected at the end of the function.
But if we do:
private void DoSomething()
{
Form2 yada;
yada = new Form2();
yada.Show();
}
Then yada doesn't get GC.
As Christian says, Dispose() will set it ready for GC, but it will take its own sweet time.
However do you really need to keep creating this form again and again, can't you declare it as an object in you main class, that you just show/hide when you need it. That will stop the memory allocation each time.
|
|
|
|
|
No, what I'm saying is this -
private void DoSomething()
{
(new Form2()).Show();
}
When Form2 is Closed (user action) Dispose(true) is automatically called by the CLR.
All fine. But after calls to GC.Collect() or GC.GetTotalMemory(true) (both of which should force GC) the form (plus all the controls for the form are never GC'd)
However,
private void DoSomething()
{
(new Form2()).ShowDialog();
}
When Form2 is Closed (user action) Dispose(true) is NOT automatically called by the CLR and shortly after, typically when further memory allocations are required the form gets CG'd.
My point is then that (new Form2()).Show(); requires that a reference to the form be promoted somewhere within the CLR (or O/S) to keep track of the form as the DoSomething() method completes immediately. The internal reference to the form is never removed, even when the form is closed (only when the app terminates) so the form (and all of the form's controls) can never be GC'd.
The typical base managed heap allocation for a complex form instance (multiple pages, multiple controls) appears to be around 1 to 2 megabytes (not including data) which remains after the form is Disposed. The application (an Mdi ERP solution) has around 500 forms and has a user base of around 150 users within the client organisation. The client decision to distribute the solution through Citrix is directly impacted by the cumulative effect of additional memory usage over 20 to 30 users on a typical Citrix server box.
So if no way can be found to force the CLR (or O/S) to relinquish the reference to the form after it is closed and therefore eventually be GC'd then the client decision to distribute the solution through Citrix will need to be seriously re-evaluated.
(Not the case for ShowDialog() which does not terminate the DoSomething() method until the form is Closed()) (therefore no promotion is necessary)
|
|
|
|
|
Instead of pounding on people to tell you something about your code, that they've never seen, why not test it out and beat on it until you get it to fail, or you manage to see that the GC does know what it's doing. The GC doesn't HAVE to collect objects if it doesn't see the need to, or, more precisely, it doesn't have to release managed memory back to Windows unless Windows wants it back.
If an object is collected, the memory goes back to the managed heap, not back to Windows!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
how to get status of process for checking if the process status is running or not.
Sanjit.rajbanshi@wlinktech.com
|
|
|
|
|
Class
System.Diagnostics.Process
Can Help U.
by methods GetProcessesbyName & GetProcesses u can find a process
then by Process Properties Like HasExited u can find is running or some necessary information about process.
Regards Amir Jalaly
|
|
|
|
|
I want to develope a control following strict MVC principles. My experience in developing custom controls using MFC goes against my current understanding of formal MVC. I realize they are patterns which are meant to be interpreted, but MFC controls seem to have tight coupling of components in the MVC triad.
For instance, if I were to develop a custom control I would likely superclass from a CView (or some other superclass). That CView acts as both the controller and the view, and sometimes has a model as a composite.
I dislike that design and I think proper MVC implementation would reduce concrete depencies.
I have considered how this could be done in straight C and the Windows SDK - later wrapping the control in a CView storing the component in a DLL or similar - Like that editor already on here.
My question is:
If I choose to support Windows only and figure I'll take a stab at C# is implementing a custom control using a strict MVC implementation possible? Do we have any articles on here about using C# with just the SDK to get around restrictions set by frameworks?
Cheers
I'm finding the only constant in software development is change it self.
|
|
|
|
|
At the end of the day, a control will always be both view, and controller. I've done MVC in C#, but I didn't use the keyboard, I used custom input devices which I was able to write into controller classes, and decouple those from the view. But, as soon as I needed keyboard support, I had to code it into the controls, because, on windows, the controls get the keyboard input.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I see what your saying, but I still find frameworks (MFC) non-conforming.
What i was thinking is developing the control using plain SDK (no framework) thus allowing me to keep strict seperation of all three components.
The controller would handle requests (via message pump) and invoke appropriate handlers which in turn would invoke the required models and update view(s).
Then I figured I could just wrap the DLL control as a CView. Obviously the control's API would expose many of the methods in the controller, model and view.
Is doing something like this possible in C#? Know of any articles on CP?
I'm finding the only constant in software development is change it self.
|
|
|
|
|
Hockey wrote: but I still find frameworks (MFC) non-conforming
To the assumption that MVC must be followed ? Yes. I used MVC because I knew that there would be 4 or 5 controllers and at least two views. In that sense, it made perfect sense, and worked really well. I doubt that MVC would have improved any of the MFC projects I ever worked on.
Hockey wrote: Is doing something like this possible in C#?
Not really, no. And, it's barely possible in C. I mean, like I said, it's still your control that recieves your keyboard and mouse messages. If you do it via a message pump, you make intercept a message with a window handle, so you know where it came from, but I still think it's a bit messy.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hello all.
I need an algorithm that will take a .avi video file and .jpg image file as input. and the output will be the .avi file with the given image overlayed on it.
can anyone help me to find a solution.
Thanks in advance.
Enamul Hoque
|
|
|
|
|
It's not an algorithm that you need. Basically, you can do this with DirectX, by creating a filter that superimposes the JPG. Or you can use WPF. Or you can decompose the AVI to frames, merge them with the JPEG, and render a new AVI.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Dear Christian,
thanks for your reply.can you explain it in more details kindly?
actually i am working with a C# program. here input will be a .avi file and a .jpg file, and the output is the .avi file with the image overlayed on it.
can i use directX or WPF in C#.
Please mention any article if you know.
Thanks again.
Enamul
|
|
|
|
|
If you use WPF, you need to rewrite your app to use it. Yes, you should be able to do this in DX, but I've not done it, I am only aware that it can be done.
I know of a component that will do it for you, it costs $800. Is this an option for you ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Just look this test method:
public unsafe void Test()
{
int x=23;
int* px=&x;
*px+=1;
Console.Write(*px);
}
I want to know when will x and px distory?
thanks!
|
|
|
|
|
destroy ?
On the next GC cycle, as they exist for far too short a time to be marked to survive it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks!
You are right,its destory
You say
-------------
On the next GC cycle,
-------------
but there are unmanaged variables,does GC collect unmanged variables?
|
|
|
|
|
Will GC clean up unsafe code too?
Regards,
Arun Kumar.A
|
|
|
|
|
GC collects all allocated memory. Unsafe doesn't really come into it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank U very much for clearing my doubt.
Regards,
Arun Kumar.A
|
|
|
|
|
Hi,
these value types reside on the stack, they disappear when the method returns.
There is no new, no object, no collection involved.
|
|
|
|
|
*sigh* I thought so, but I wasn't sure. Certainly, I knew that unsafe wasn't going to change anything.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
It should also be mentioned that the code isn't guaranteed to work if the variables hadn't been allocated on the stack.
If it uses a real object that is allocated on the heap:
public unsafe void Test() {
string x = 42.ToString();
string* px = &x;
*px += 1;
Console.Write(*px);
}
The variable x is still allocated on the stack, but it is a reference to a string object that is allocated on the heap. If you copy the reference to a pointer, you will get the current location of the string in memory, but as the garbage collector can move objects in the heap, there is no guarantee that the string will stay in that location. It can be moved to another location at any moment, and the garbage collector will update the reference x to point to the new location, but it will not update the pointer px.
---
single minded; short sighted; long gone;
|
|
|
|