|
Hello,
peterson@brfree.com.br wrote: When you say to disconnect a delegate in the dispose method, that includes even the delegates generated by visual studio, like the delegate for a click event of a button?
Good question!
The answer is no!
What you have to worry about is for instance:
You have an Usercontrol.
You have an UserManagementclass which provides an event, lets say "StatusChanged".
At startup you instanciate your management class once. This class will always be in memory till you end the program.
Then your Form will be instanciated with your UserControls on it.
This Usercontrols are getting a reference to this Managementclass in the constructor and connect the event StatusChanged (mymanagementclass.StatusChanged+=...).
In that case your UserControls Dispose method has to implement "mymanagementclass.StatusChanged-=...", otherways there would always be the reference to the Management class and the GC could not free the UserControls memory.
What you also can do to help the GC finding not referenced objects is setting them null after disposing.
In my example you could add "mymanagementclass=null" in the Dispose method of your UserControl.
peterson@brfree.com.br wrote: And I see a lot of objects listed as undisposed items. That means items that have been collected by the garbage colector whitout beeing properly disposed. This objects are Labels, Buttons, TextBox, Fonts and a few others. I would also be worried about that!
Looks like you are not Close() complete Forms which are shown with Show(), and always instanciate a new Form.
Is it possible that you are doing so?
Hope it helps!
All the best,
Martin
|
|
|
|
|
I close the forms, for sure... It's wierd... between the undisposed items it keeps acumulating 3 types of my userControls. The project has 7 other types of userControls that seems to be diposing Ok.
And this userControls that are not beeing properly disposed have labels and buttons in them. I believe that this may be the cause of the labels and buttons undisposed in the profiler's list.
I have left the application running for several hours, using DataLoad to keep openning and closing screens. Even though Memory Profiler shows an increase in theses undisposed items, the memory used by the application remains in 100MB - 120MB (reported by task manager). So it doesn't seems to have a leak, like the profiler sais. I don't know if I can trust 100% on the profiler. It´s documentation is not very clear in some poits...
Peterson
|
|
|
|
|
Hello,
Peterson Luiz wrote: And this userControls that are not beeing properly disposed have labels and buttons in them
Is there something else special about that UserControl?
Peterson Luiz wrote: Even though Memory Profiler shows an increase in theses undisposed items, the memory used by the application remains in 100MB - 120MB (reported by task manager).
Maybe the GC is able to free these memory although it is not disposed properly, who knows?;)
Peterson Luiz wrote: I don't know if I can trust 100% on the profiler. It´s documentation is not very clear in some poits...
That's true, but normaly it shows always too much because it also calculating the unmanaged resorces.
At the link I gave you, you could download a trial version of .netmemprofiler professional, which also shows the unmanaged resorces apart from .Net recorses!
I would recommend making snapshots from time to time and look for delta instances!
All the best,
Martin
|
|
|
|
|
peterson@brfree.com.br wrote: I've been told to use System.Runtime.InteropServices.Marshal.ReleaseComObject() to free the resources of my COM object. Is that necessery?
Yes!
|
|
|
|
|
Hello
I want to share a folder through coding, within a network.
Thanks
Devesh Mishra
|
|
|
|
|
Hi,
You can use the "SetAccessControl" method of the DirectoryInfo class for this purpose.
Manoj
Never Gives up
|
|
|
|
|
I have a table of data 'properties' containing
PropertyID int ident,
PropertyName varchar,
PropertyRequired bit,
PropertyType varchar,
PropertyValue varchar
I'm looking to create a BLL with a class MyProperties and an enum MyPropertyTypes
The MyPropertyTypes are Number, Text, Date, Boolean, ListFixed, ListCustom, Range
For the Number,Text,Date,Boolean only a single value is present but for the rest they can have more than one value
what is the best way to model a class/es to incorporate the properties common to all (ID, Name, Required, Type) and the properties specific to each PropertyType which can vary by both number and object type?
Thanks in advance
Mac.
|
|
|
|
|
class MyBase
{
int ID;
string Name;
bool Required;
string Type;
}
class Derived<T> : MyBase
{
T type
}
-- modified at 10:32 Wednesday 30th May, 2007
only two letters away from being an asset
|
|
|
|
|
Thanks Mark,
I'm still not sure though how I could load the classes if I don't know the type in advance?
Take the following scenario
Property 1 is a number
Property 2 is a range
MyProperty oProperty = new MyProperty(1);
if(oProperty.Type == MyPropertyType.Number)
{
//load property again?
MyNumberProperty nProp = new MyNumberProperty(1);
nProp.Value = 1;
}
MyProperty oProperty = new MyProperty(2);
if(oProperty.Type == MyPropertyType.Number)
{
//cast to the correct type?
MyRangeProperty rProp = (RangeProperty)oProperty;
rProperty.StartValue 1;
rProperty.EndValue = 100;
}
or another method, generics perhaps?
Thanks in advance
Mac.
|
|
|
|
|
wwwlicious wrote: MyProperty oProperty = new MyProperty(2);
You are creating a instance of the base class here. You create the instance of the specific type and use it. Also, when you will create a instance of the specifix type it will contain the type information.
i.e.
MyRangeProperty rProp = new MyRangeProperty();
rProp.StartVale = 1;
rProp.EndValue = 100;
rProp.type = Number //See here you need to set the type while creating instance.
Now, the instance of MyRangeProperty have all the info. Even if you cast it to base class, you will be able to access the "type" info, to decide what type of properties has been stored there.
Manoj
Never Gives up
|
|
|
|
|
Thanks Manoj,
how do I know which type to create an instance of in the first place if I start with only an ID though?
Thanks in advance
Mac.
|
|
|
|
|
See, whenever you get the info regarding which type you want, you can create that type of properties and get the values set. Why do you want to create a abstract type of properties? Sorry, but seems I am not able to understand your requirement properly.
Manoj
Never Gives up
|
|
|
|
|
ok a bit more explanation required I think. The properties apply to products, each product can have any number of properties attached to it.
The requirement is for properties to be shared for all products and strongly typed.
Each type has validation rules which are both common and specific per type
All properties must have a name
Required properties must have a valid value
Number can have a min + max numeric range along with prefixes and suffixes
Text can have max character limit, no pre/suffix
Boolean, no pre/suffix
Date, no pre/suffix, min + max date range
List, no pre/suffix, unlimited string values
Example
Product 1 has 4 properties color, weight, temperature range and optional
color is a list type
weight is a number type
temp range is a range type
optional is a boolean type
The property table has
ID Name Prefix Suffix Min Max DefaultValue
1 color Black|White|Red|Green
2 weight kg 0 9999 0
3 temp ºC -273 20000 -10|70
4 optional 1
The product property table holds
ID PropertyID Ordinal Required Value
1 1 1 1 Red
1 2 2 1 0.4
1 3 3 0 20|40
When a product is loaded, it contains a collection of Properties. the idea is to access the collection using and index and return an abstract or generic type of some kind to work with.
Hope that all makes sense. Its a bit more complex than I suggest but that's the basics.
Thanks in advance
Mac.
|
|
|
|
|
Since this sounds like a homework assignment I'll give you expand on what I've already said and let you complete it.
public class Property<T><br />
{<br />
private T m_Value;<br />
private string m_Name;<br />
<br />
public Property(string name, T value)<br />
{<br />
m_Name = name;<br />
m_Value = value;<br />
}<br />
<br />
new public Type GetType()<br />
{<br />
return typeof(T);<br />
}<br />
}<br />
<br />
Property<int> propWeight = new Property<int>("weight", 1);<br />
Property<bool> propOptional = new Property<bool>("optional", false);<br />
<br />
only two letters away from being an asset
|
|
|
|
|
Thanks Mark for your example, it's definately not a homework assignment (I wish!). I generalized the example quite a lot to hopefully explain the issue clearly.
I have looked at generics but I still can't get my head around how I could have a constructor to load a property from an ID without knowing the type in advance.
I won't have the name and value with which to load the property as in your example above, just an int ID.
<br />
Property propAny = new Property(1);<br />
<br />
Property<?> propAny = new Property<?>(1);<br />
? =
sorry if I'm missing the obvious here but I don't see how this works.
Thanks in advance
Mac.
|
|
|
|
|
You are going to have to rethink your architecture then. Other than using object for everything there is no way I know of to support all cases of unknown types.
only two letters away from being an asset
|
|
|
|
|
ok will have a think about it, I don't like the idea of using object much, seems like a hack approach but I liked the idea of having the values strongly typed each with the business rules encapsulated.
thanks for the help though, much appreciated.
Mac.
|
|
|
|
|
can anybody help me reading the elements of xml document???
Regards
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
Get the document element using following code:
XmlDocument xmlDoc = new XmlDocument();
xmlNode root = xmlDoc.DocumentElement;
XmlNode node = root.FirstChild;
Now you can traverse all nodes of xml file depending upon the structure of file, using a simple while loop....
while (node != null)
{
node = node.NextSibling;
// or
node = node.FirstChild;
// etc.
}
Hope that helps....
..................
QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!
|
|
|
|
|
Hi!
I am using datagridview control to display records, in my datagridview mostly more than 50000 records are displayed. after every 5 seconds the control is refreshed and new datasource is assigned to it.
Now when i am scrolling the datagridview and meanwhile timer refreshes the control, it brings me back to the first row of control. which is quite annoying when you are on 30000th row.
I want to maintain the view of control after it is refreshed. I tried to save the e.oldValue of ScrollEventArgs in dgv1_Scroll eventhandler and then after refresh assigning it to e.newValue but it did'nt worked....
I achieved this by saving the index of selected row and then after refresh selecting that row again, but i want to do it without selecting any row...is it possible to save the scoll value and then restore it....?
Thanks in advance...
Regards,
Affan Ahmad Toor
.....................................
QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!
|
|
|
|
|
Hi Codeguru´s,
Can somebody help me - i´ve a big problem:
In my C# Windows Application i want to get all entries from our MS Exchange Server 2003 public Folger (Calendar).
have someone an idea?
bye
Markus
|
|
|
|
|
Is there any way to integre the DIVX player.
else
Is there any light movie player controller which can support all type of movies, if the relavent codec is installed.
any help is appriciated
Ravikumar
|
|
|
|
|
Hi
how can i read xml string in c#??
Regards
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
hi
XmlDocument doc = new XmlDocument();
doc.LoadXML(xmlString);
regards
|
|
|
|
|
If the user input data in textbox, i want to get that data and store it.
Just like, Console.Write(); / Console.Read();
---// in textbox????
thanks in advance,
to know everything is to know yourself...
|
|
|
|