|
As Christian pointed out, welcome to a garbage collected world. At some point after your object is disposed, the GC will eventually free the memory. Calling Dispose only helps mark the object as collectible.
Rick van Woudenberg wrote: Even unmanaged resources eventually have to rely on the GC to get cleaned up
Unfortunately, the GC does not know how to free unmanaged resources. That is the reason to call Dispose when you are done using the object.
For a more detailed look at how to implement Dispose , check out the following article:
http://www.codeproject.com/useritems/idisposable.asp[^]
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Scott Dorman wrote: Calling Dispose only helps mark the object as collectible.
That's incorrect. Calling Dispose has nothing to do with garbage collection, it is required only to release the resources held by the object immediately. The GC only checks for references to an object to find out if it's eligible for collection.
|
|
|
|
|
You are correct...that statement was inaccurate. However, when the GC does collect an object it will call the Dispose method if it hasn't already been disposed.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Scott Dorman wrote: However, when the GC does collect an object it will call the Dispose method
I guess you meant Finalize instead of Dispose.
|
|
|
|
|
Arrrrrgggggg!!!
Yes, I did. It's been a long day...and it's only half over. I guess that's what happens when you don't get more than a few hours of sleep the night before.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Yeah, one thing a lot of people miss is the Dispose/Finalise pattern.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hello,
To make sure if your class is really ready for the GC, call GC.Collect() just for testing (Of course its not recomended to leave it in your code).
It could also be possible that the FormNetworking instance holds a connection too an other custom class (for example over an eventhandler), and so the GC will not clear the memory!
I also would recomend too check youre code with .Net MemoryProfiler (freeware).
All the best,
Martin
|
|
|
|
|
Can any Body tell me what is Bug Tacking System.
|
|
|
|
|
It's a system, right, for tracking ( are you still with me ? ), bugs.
In other words, it's something you could easily have googled for, or gone to wikipedia, it's a system that is used to keep track of known issues in your software, and when/how you fix them
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thankx for replying Christian Graus.
|
|
|
|
|
Hi boys & girls,
I would like to implement automatic updates to my application (which is in C#).
I’m quite confused, I heard that there is ClickOnce\ Updater Application Block built in .Net 2005, is it correct?
How do I use it?
Were can I find relevant tutorials?
In the MSDN site I could find only the Updater Application Block for .Net 2003
Thanks,
Gil
May the source be with you
|
|
|
|
|
I have been working on trying to write a directory watcher service.
One of the requirments is that it be able to watch multiple
directories, not sub directories of one parent directory, but just
multiple directories.
Using FileSystemWatcher in .Net
Thanks in Advance
Hari
|
|
|
|
|
well, I don't see the problem..
just use some a number of FileSystemWatcher objects..
life is study!!!
|
|
|
|
|
Hi You can do it creating Multiple FileSystemWatcher Objects.
Here is a code snippet of it.
//Folder to be monitered are placed in Appconfig seperated with ;
char[] delimiterChars = { ';' };
string FoldersNames = ConfigurationSettings.AppSettings["FoldersToMonitor"];
string[] fileNames = FoldersNames.Split(delimiterChars, System.StringSplitOptions.None);
foreach (string s in fileNames)
{
FileSystemWatcher Clientwatcher = new FileSystemWatcher();
Clientwatcher.Path = s;
Clientwatcher.Filter = "*";
Clientwatcher.NotifyFilter = NotifyFilters.LastAccess;
// Clientwatcher.Created += new FileSystemEventHandler(OnChanged);
Clientwatcher.Changed += new FileSystemEventHandler(OnChanged);
// Clientwatcher.Renamed += new RenamedEventHandler(OnRenamed);
Clientwatcher.EnableRaisingEvents = true;
fw.Add(Clientwatcher);
}
Enjoy.
Satya
|
|
|
|
|
Sorry forgot the declaration of fw. It's an arraylist.
ArrayList fw = new ArrayList();
Satya
|
|
|
|
|
Please see the following link. i think it will help you.
http://www.codeproject.com/useritems/AdvancedFileSystemWatcher.asp
asd
|
|
|
|
|
hi friends,
I had a problem , i am takin a survey in which i need to give value to the answers submitted by the user and take the average of it , please send me the solution
vinay
|
|
|
|
|
viru04 wrote: give value to the answers submitted by the user
We cannot help you with this unless you give some information on the type of answers.
viru04 wrote: take the average of it
Sum up the values and divide by the number of values.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
isn't that a mean
Russell
|
|
|
|
|
Hello,
In our firm, we use DataSet, DataTable, and Collectoin as Datasource for a DataGrid. But in 3 tier architecture I found that its slower when data is returned as a Collection Class from Data Layer, simply calling the Data Access function in the Data layer (which returns a DataTable) from Presentation layer is much faster. But this comes at the expense of breaking the architecture.
So which is the best data access object, Dataset (strongly typed or normal one), DataTable, or a Collection class? Can anybody share their thoughts.
Regards,
Blumen
Blumen
|
|
|
|
|
Hi,
I think is better to use datasets instead of collection because you can fill it directly from the adapter in the data access layer... You simplify... and you can do selects to get specific data from the table...
At last, I prefer dataset instead of datatable because If I need I can return two tables (and if is necessary I can use relations).
Thats my point of view. There're persons who prefer work with collections because they think that more easy to maintain...
|
|
|
|
|
il_masacratore wrote: Thats my point of view. There're persons who prefer work with collections because they think that more easy to maintain...
Not easier to maintain, but easier to work with in an OO fashion. Here's a quick example:
public interface IValid
{
bool IsValid { get ; }
}
public void ItemBase
{
protected virtual string TrimString(string value, maxLength)
{
if (value == null || value.Trim().Length == 0)
return value;
value = value.Trim();
if (value.Length > maxLength)
{
value = value.Substring(0, maxLength)
}
return value;
}
}
public void Customer : ItemBase, IValid
{
private string _forename;
private string _surname;
public Customer(string forename, string surname)
{
_forename = TrimString(forename, 30);
_surname = TrimString(surname, 30);
}
public string Forename
{
get { return _forename; }
set { _forename = TrimString(value, 30); }
}
public string Surname
{
get { return _surname; }
set { _surname = TrimString(value, 30); }
}
public bool IsValid
{
get
{
bool valid = false;
if (_forename != null && _forename.Trim().Length > 0)
valid = true;
return valid;
}
}
}
public abstract class BaseCollection<T> where T : IValid
{
private List<T> _list;
public List<T> Collection
{
get { return _list ; }
set { _list = value; }
}
public void Add(T value)
{
if (value.IsValid)
{
_list.Add(T);
}
else
{
throw new Exception("Invalid object.");
}
}
public abstract void Fill();
protected abstract void AddRow(IDataReader dr);
protected void Add(IDataReader dr)
{
if (dr.HasRows)
{
while (dr.Read())
{
AddRow(dr);
}
}
}
}
public class Customers : BaseCollection<Customer>
{
public override void Fill()
{
using (SqlConnection conn = new SqlConnection(Utilities.ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = "GetAllCustomers";
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
Add(dr);
}
}
}
}
protected override void AddRow(IDataReader dr)
{
string forename = dr.GetString(dr.GetOrdinal("forename"));
string surname = dr.GetString(dr.GetOrdinal("surname"));
try
{
Add(new Customer(forename, surname));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
Notice that you only have to implement the two methods in the inherited collection class to get the benefits of adding data from the database into your collection. It is trivial to extend this functionality to include the ability to search for records, save or delete them. Now, your client code will be a lot easier. Which of these do you think is easier to use?
customer.Surname = "Smith";
or
ds.Tables[0].Rows[0]["surname"] = "Smith";
What happens when you change the field name in the database from surname to cust_surname. In the implementation above, you only need to change this reference in the Customers class. If you are using a DataSet, then you have to hunt them down in every location that they are referred to and you could well end up missing them. Plus, what happens if you've exposed this as a web-service? The DataSet is a Microsoft implementation, so if a Java application is going to consume the DataSet then they are going to have to wrap up a heavy duty object. Plus, the renaming problem becomes much worse if you have changed the name of the column in the database. You are now asking everybody who consumes your DataSet to change their references to the field name. By the way, you can still bind the Collection property to items like a datagrid because this is a collection class.
I know that the abstraction seems to be a complete PITA, but once you have created a base object that you are happy with, you can easily reuse (and extend) this functionality. With the use of a tool like CodeSmith, creating the other classes becomes trivial.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
I'm agree with you. But, at all, we're always depending on timing... In some cases we will do the best practices and in others we will do a shoddy work...
PD: If we use constants to access fields, we unify and we only have to change its value...
|
|
|
|
|
I agree that time constraints are a problem, but this is where a tool like CodeSmith comes into its own. We have a base set of objects that we have created and fine-tuned (for things like the base collections, the base item objects and so on). We then generate our standard stored procedures implementation classes and unit tests from this. This means that, once we have a data model defined, we can generate the entire DataLayer in one go.
Anything like validation that needs to be performed is handled in a derived class, so that if we regenerate the code, we don't lose our custom logic.
Yes, getting the base objects and CodeSmith templates into a fashion that you are happy with does take some time. But once you are happy with the way your objects work, generating new classes takes almost no time.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi again,
I will try it... You know any published example of use??
Thanks
|
|
|
|