|
Pls. refers once purpose of Dispose pattern and supressfinalize method of GC.
|
|
|
|
|
|
Kindly change the question and state the correct problem there......
|
|
|
|
|
Look, I appreciate that you're trying to be helpful.
My initial question does state the correct problem: I'm trying to release memory right before a generation 3 garbage collection.
|
|
|
|
|
The question is already correct and unambiguous. It seems you got it wrong.
|
|
|
|
|
AFAICT, there is no way to tell when a GC is going to occur without diving into the CLR-specific API. Short of creating your own version of the CLR, I don't see how you can do it.
|
|
|
|
|
Yeah, I agree. The techniques described for .Net 3.0 seem a bit sketchy.
I ended up using an algorithm that checks GC.GetTotalMemory() on a periodic basis. As a consequence, the system administrator will have to tune the program to give it a target RAM amount to occupy.
|
|
|
|
|
Idea: Maintain a queue of strong references to the most recently used objects. This prevents them from being garbage collected. When an object is used, move it to the front of the queue. When you insert a new object at the front of the queue, delete the strong reference at the tail of the queue if the queue size is above a certain threshold.
If recently-referenced objects are more likely to be referenced again, this cache will avoid re-reading them from disk.
An enhancement: Instead of just a plain queue, keep the items in keyed storage (hash table, binary tree, etc), and maintain the queue as a doubly-linked list, implemented by Previous/Next fields in your items. This will let you quickly look up an object which may be in your cache. Adjust the Previous/Next fields to move it to the head of the queue. You'll also want to maintain external pointers to the head and tail of the queue.
Hope this helps.
|
|
|
|
|
That's pretty much what I decided to implement, although I'm experimenting with GC.GetTotalMemory() to determine how many items to pull off of the queue. I keep building the queue until GC.GetTotalMemory() reaches a target size, and if GC.GetTotalMemory() goes above a certain threshold, I remove two or three items.
I'm not quite sure how the linked list plays in: I'm keeping references with a dictionary, and the queue is used to increment / decrement an access count.
Anyway, thanks!
|
|
|
|
|
It's your app, so you know if this is possible, but I would try to resturcture the logic so I do not need to be accessing the same file repeatedly to the point where I'm keeping a cache of files. If you are only accessing a file once every 10 minutes, I would assume that the performance gain from caching the string will be small.
If the Mono garbage collector works like the .NET one, the Large Object Heap may be what you need. (I do not claim to be a Large Object expert. I've only read the first article that comes up on Google about it. [1][2]) If the resulting string from the file is >85K in size, the string should get placed on the LOH and will thus not get collected except in a full collection. If the files are smaller than that and you still need to cache them, you may be able to hack something together with a large finalizable object, but I wouldn't recommend it.
If that doesn't work, you probably need a more defined caching policy than "keep them as long as the process has memory."
|
|
|
|
|
|
Hi,
Did you think about implementing a paging algorithm (LRU, clock page replacement) ?
As for the dispose, I recommend that in your dispose you set the memebers to null where possible for faster memory reclaims.
|
|
|
|
|
I ended up using a combination of a queue and access counters. Whenever an object is accessed, I call GC.GetTotalMemory() to determine how many objects to de-reference.
Anyway, this thread has nothing to do with Dispose.
|
|
|
|
|
Control[] controlArrays = new Control[3];
controlArray[0] = textbox1;
controlArray[1] = textbox2;
controlArray[2] = textbox3;
for(int i = 0; i < controlArrays.Length; i++)
{
if(controlArray[i] is TextBox)
(TextBox)controlArray[i].Text = "My Array #" + i.ToString();
}
Thanks.
modified on Friday, December 4, 2009 12:13 AM
|
|
|
|
|
You could create an array of type System.Windows.Forms.Control instead of object. After all, if you are only going to keep textboxes inside your array it does not make sense to use an object type. You could even use System.Windows.Forms.TextBoxBase if you really just need to store text boxes.
Since you know your array elements anyway, you could also do something like - Control[] controlArrays = new Control[]{textbox1,textbox2,textbox3};
Looks neater, thats all .
I'm no expert, but I dont see any problems in storing controls inside an array.
|
|
|
|
|
I got an error there, i really meant Control, not object. Thanks.
I asked because I saw an article regarding making Control Arrays in C# but
its longer and a lot more complicated.
|
|
|
|
|
If you are going to put only textboxes in the array, create an array of TextBoxes. That will avoid all that casting.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Consider using a List instead of an array, unless you have specific needs that dictate using an Array. The List class will automatically re-size as you add objects, yet you can still iterate and reference by index.
For example:
List<Control> controls = new List<Control>();
controls.Add(textbox1);
controls.Add(textbox2);
controls.Add(textbox3);
controls.Add(textbox99999999999);
for(int i = 0; i < controlArrays.Length; i++)
{
if(controls[i] is TextBox)
(TextBox)controls[i].Text = "Element #" + i.ToString();
}
|
|
|
|
|
Use Arraylist and then filter the Textbox controls from the form controls to get collection of controls.
visit the link for more info : <a href="http://www.dreamincode.net/forums/showtopic45666.htm">http:
modified on Friday, December 4, 2009 5:39 AM
|
|
|
|
|
Use a Generic List. It is much faster, resizes automatically and also avoids runtime type casts.
List<TextBox> textBoxes = new List<TextBox>():
textBoxes.Add(textBox1);
textBoxes.Add(textBox2);
textBoxes.Add(textBox2);
int i =0;
foreach(TextBox textBox in textBoxes) {
textBox.Text = string.Format("My Array {0}", ++i);
}
|
|
|
|
|
Hi,
take a look at the System.ComponentModel.CollectionBase class.
you can write your own ControlCollection and do various operations on Adding to collection..
greetz
|
|
|
|
|
That looks OK, but why would you want to?
|
|
|
|
|
I Have a string
<Parameters>
<UserProfileState>0</UserProfileState>
<Parameter>
<Name>Report_Parameter_0</Name>
<Type>String</Type>
<Nullable>False</Nullable>
<AllowBlank>True</AllowBlank>
<MultiValue>False</MultiValue>
<UsedInQuery>False</UsedInQuery>
<State>MissingValidValue</State>
<Prompt>Report_Parameter_0</Prompt>
<DynamicPrompt>False</DynamicPrompt>
<PromptUser>True</PromptUser> </Parameter>
<Parameter> <Name>Report_Parameter_1</Name>
<Type>String</Type> <Nullable>False</Nullable>
<AllowBlank>True</AllowBlank>
<MultiValue>False</MultiValue>
<UsedInQuery>False</UsedInQuery>
<State>MissingValidValue</State>
<Prompt>Report_Parameter_1</Prompt>
<DynamicPrompt>False</DynamicPrompt>
<PromptUser>True</PromptUser>
</Parameter> </Parameters>
I want to do string manipulation with this and i want to
<Name>Report_Parameter_0</Name>
they are 2 <name>
its not xml ..!
how to do in good method.!
any help is greatly appreciated..!
|
|
|
|
|
Can you use C# regular expressions for this?
|
|
|
|
|
Ty For Your Reply..!
How Can i get the value of
<<Name>Report_Parameter_0</Name>
Report_Parameter_0 for this one..!
|
|
|
|