I think I have a list that uses all my memory. let me explain what I'm doing
I have a device from which I take messages, I timestamp them, and I add them to sqldatabase
myConnection.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO Messages (Time, Message) Values ('" + DateTime.Now + "', '"+sqlMessage+"')", myConnection);
cmd.ExecuteNonQuery();
myConnection.Close();
UpdateTable();
here as i update my list:
myConnection.Open();
myCommand.Connection = myConnection;
adapter.SelectCommand = myCommand;
myCommand.CommandText = "SELECT * FROM Messages";
DataSet ds = new DataSet();
adapter.Fill(ds);
lvwMessages.DataContext = ds.Tables[0].DefaultView;
myConnection.Close();
when I leave this for a while, my program usually runs out of memory. I assume that in listview too many posts are loaded from the database. but let me say that I have 15 lines of messages that I need on the screen. how do i load only 15 that i need and then pop those that don't need to be removed from memory and load new ones?
source
share