|
So you need to look at what the "missing code" is doing.
Because is the rows already exist, just checking on the content won't increase memory.
I know you aren't executing "just the code you showed us" in isolation: it's part of a bigger app.
So you need to look at what else is going on: any other threads, what the message stuff is doing, and such like.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
First of all, never use TaskManager to diagnose memory issues. It's not very good at it.
Secondly, without seeing what's going on in that missing section of code, it's impossible to know what's going wrong. The obvious suggestion is that you keep on filling something in there, which would suggest that it's an issue with your logic - i.e. you should probably be removing something in there as well. Beyond that, we cannot tell because you have given zero relevant code.
|
|
|
|
|
i use this
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
Value = dataGridView1.Rows[i].Cells[sel_index + 2].Value.ToString();
if (dataGridView2.Rows[i].Cells[1].Value == null || dataGridView2.Rows[i].Cells[1].Value == string.Empty || dataGridView2.Rows[i].Cells[1].Value.ToString().Trim().Length == 0)
{
dataGridView2.Rows[i].Cells[1].Value = Value;
dataGridView2.Rows[i].Cells[1].Style.ForeColor = Color.Red;
}
else { }
}
|
|
|
|
|
There is nothing in that code that should cause an out of memory exception. I would suggest that the problem doesn't lie here, and that it's somewhere else. If you put a breakpoint in this code and step through it, you will probably find that it behaves as expected.
|
|
|
|
|
dataGridView2.Rows[i].Cells[1].Value.ToString().Trim().Length == 0
Value.ToString() creates a copy of "Value". .Trim() then creates a copy of that. If you have a lot of data in Value you have it x3.
If Value is type "object" but you know it contains a string then do a cast rather than ToString, and for checking if something is empty use string.IsNullOrWhiteSpace rather than a trim and length check.
string.IsNullOrWhiteSpace((string)dataGridView2.Rows[i].Cells[1].Value)
|
|
|
|
|
hello;
I have just started using VS2008 C# for windows mobile. I cannot make my label.text continuously display data, I verify the information is being passed but the form is not displaying the information. I tried this simple piece of code and it only displays the last value. please help.
namespace datatran
{
public partial class frmSend : Form
{
int i = 0;
int value;
public frmSend()
{
InitializeComponent();
}
private void btnSend_Click(object sender, EventArgs e)
{
value = Convert.ToInt16(txtBoxSend.Text);
while (i < value)
{
lblCount.Text = i.ToString();
lblCount.Show();
i++;
}
}
}
}
|
|
|
|
|
The reason why it's not working as you expect is that the thread executing your event handler method is also responsible for updating the screen - which it can't while it's executing the event handler method. Once it's done executing the event handler it updates the screen - once, and obviously with the last value that was assigned to the label text. One solution for this would be to employ a Timer (MSDN-Doc[^] / Codeproject Tutorial[^]) which provides you a simple way of changing the label text and updating the screen simultaneously.
I guess this was a desperate measure:
lblCount.Show(); - you don't need to do that each time you update the label text.
|
|
|
|
|
thanks for the idea on the timer, I tried it with the correct time interval but it still did not work. Not sure why.
|
|
|
|
|
The following code only updates the text with the current value of i through each step of the While Loop. So once the While loop is done, the text will of course be only the LAST value.
while (i < value)
{
lblCount.Text = i.ToString();
lblCount.Show();
i++;
}
If you are wanting the textbox to show each step through the While Loop, then try this:
lblCount.Text.Clear();
while (i < value)
{
lblCount.AppendText = i.ToString() + "\r\n";
i++;
}
|
|
|
|
|
thanks, but VS2008 do not support Append
|
|
|
|
|
I'm sorry, I just realized it is a label, not a textbox.
Not sure but this may work:
while (i < value)
{
lblCount.Text = lblCount.Text + i.ToString() + "<br/>";
i++;
}
|
|
|
|
|
|
Thanks all for the help, The answer to my issue is to use a text box instead. This works for me.
while (i < value)
{
textBox1.Text = i.ToString() + "\r\n";
i++;
}
|
|
|
|
|
that's a workaround. not a solution.
Not that, that's a bad thing, but it is important to note the difference.
|
|
|
|
|
It seems like it is looping through all the values and making the label display all of them. It is probably doing this so fast that you only see the last set value.
If you want to see all the values, maybe try lblCount.Text += i.ToString() + " " to display all the values side by side. If you do this, remember to clear out the label before looping.
|
|
|
|
|
thanks, I'm using the text boxes instead of labels.
|
|
|
|
|
Hello folks, I have a problem (as well as with the English language ^ __ ^) with a web service that I have already created and works fine. Now I have to add a header that contains an ssl certificate (.cer) but do not know how to do. Can anyone help? Place below the important part of the code. Thank you all!
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportWithMessageCredential;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
Uri cUri = new Uri("https://Service?wsdl");//reserved data
EndpointAddress ea = new EndpointAddress(cUri);
CVPClient client = new CVPClient(myBinding, ea);
|
|
|
|
|
The method that has the following signature in the code bellow:
“protected virtual void SetProperty<T>(ref T item, T value, [CallerMember] string propertyName = null)”
What type of method is this. The body of the method is in the code in this post.
Thanks,
Truck
protected virtual void SetProperty<T>(ref T item, T value, [CallerMember] string propertyName = null)
{
if(!EqualityComparer<T>.Default.Equals(item, value))
{
item = value
OnNotifyPropertyChanged(propertyName);
}
}
|
|
|
|
|
It's a virtual Generic method, returning no value.
The Generic bit is the <T> - which means that the type of the parameters "T" is defined by the context in which it is called, not when it is defined.
MSDN[^]
You can call it with integers, or strings, or Buttons - it will work with them all.
The virtual bit allows derived classes to override the method to work differently if they wish.
MSDN[^]
If they override it, then the later version will be used when teh method is called. If they don't, this version will.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
i like to know in details and want to visualize how memory is allocated in dotnet program. sorry because i will be asking few question. so please answer point wise in detail.
1) suppose i have class called employee which has data member called empNo, Name and Salary. so i like to know when we will create object of employee then how memory will be allocated ?
2) where memory will be allocated for employee object? in heap or stack?
3) why memory is allocated in heap for object and local variable in stack?
4) i hear some time memory is allocated in heap for local variable but when?
5) where actual data is stored like employee name or salary in heap or stack? if in stack why? why not in heap?
6) i heard that memory is allocated for static class in high frequency heap........what is high frequency heap and how it is different than normal heap?
tbhattacharjee
|
|
|
|
|
I'm not going to answer your questions - but not because I'm nasty: because the questions are wrong!
The distinctions between stack and heap isn't as simple as you might think: and a variable in C# probably isn't what you think it is either - which is at the root of the "wrongness" of your questions.
So: what is a variable?
Simply put, a variable in a method is always allocated on the stack - but it's content may or may not be on the stack, depending on what type of data the variable refers to. If it's a ValueType , then the variable is allocated enough space to hold the whole value: and int is a ValueType , and so is a Point . These are always the same size: you cannot extend the size of a ValueType in any way.
If it's a reference type, then the variable always holds a reference to the actual data, rather than the data itself, and again the variable is a fixed size - only this time it is always either 32 bits or 64 bits depending on the environment your code is executing in. String is a reference type, so is any array.
And that's important: because all reference values are allocated on the Heap: never, ever on the stack.
int i = 6; Integers are ValueTypes , so "i" is on the stack, and is the value of the integer - in this case 6.
Button b = new Button(); Button is a reference type, so the actual data for the new instance is stored on the heap - but "b" is the variable and it is located on the stack, and contains a reference to the actual instance.
But...that doesn't mean that all ValueType instances are on the stack - they aren't: they can be embedded in reference type instances:
public class MyClass
{
public int Value;
}
...
MyClass mc= new MyClass();
mc.Value = 6;
MyClass is a reference type (all classes are reference types, all structs are value types) so the instance data is on the heap, and that includes the value type integer "Value" it contains. "mc" is on the stack and holds a reference to the heap based actual data.
From here it starts to get very, very complicated - there is something called "boxing" to consider as well, where a stack based value is copied to the heap and passed as a reference - far too complicated for a little text box like this one!
Get a c# book - they all explain this with pictures (which helps a lot) and when you've read it have a look at this: Using struct and class - what's that all about?[^] - it explains a bit more about it, but it's not exactly beginner friendly!
[edit]Typos![/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 26-Feb-15 10:11am.
|
|
|
|
|
+5 !
small typo here:
OriginalGriff wrote: copied to the head
|
|
|
|
|
Fixed! (Along with a couple of others... )
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
thanks for your time and answer. you said : that's important: because all reference values are allocated on the Heap: never, ever on the stack.
int i = 6;
Integers are Value types, so "i" is on the stack, and is the value of the integer - in this case 6.
i heard that reference type stored in heap and their corresponding value stored in stack.
you said but this is not very clear MyClass is a reference type (all classes are reference types, all structs are value types) so the instance data is on the heap, and that includes the value type integer "Value" it contains. "mc" is on the stack and holds a reference to the heap based actual data.
is there any book which i can download its pdf version which you read and tell me which chapter discuss memory management related things for c# or any other book which easily help me to understand with picture how and when data stored in heap and stack.
share knowledge if you know what is high frequency heap?
tbhattacharjee
|
|
|
|