Arrays and OutOfMemoryException

F

Fernando Casero

Hi, I'm programming on Visual C# Express Beta 2 and I have the following
code:

class MyClass
{
int[] a = new int[30]
int [,] b = new int[10,20]

public int SomeMethod()
}

class OtherClass
{
MyClass[] cls = null;

public void DoSomething()
{
int a = 3000;
cls = new MyClass[a];
}
}

class program
{
OtherClass other = new OtherClass();

public int main()
{
other.DoSomething()
}
}

When running on Debug , this code works as expected, but on Release I get an
OutOfMemoryException allocatting the array on "cls = new MyClass[a]" when
calling "DoSomething"

Can someone help me to solve it?

Thanks in advance

Fernando
 
G

Guest

Fernando Casero said:
Hi, I'm programming on Visual C# Express Beta 2 and I have the following
code:

class MyClass
{
int[] a = new int[30]
int [,] b = new int[10,20]

public int SomeMethod()
}

class OtherClass
{
MyClass[] cls = null;

public void DoSomething()
{
int a = 3000;
cls = new MyClass[a];
}
}

class program
{
OtherClass other = new OtherClass();

public int main()
{
other.DoSomething()
}
}

When running on Debug , this code works as expected, but on Release I get an
OutOfMemoryException allocatting the array on "cls = new MyClass[a]" when
calling "DoSomething"

Can someone help me to solve it?

Thanks in advance

Fernando


please explane more ,, it s not clear
 
P

Pohihihi

Fernando,

First, If this is C# code you are trying to compile then it will not
compile. It is buggy with small syntex errors.
Second, after fixing those syntex errors this program it should not give you
any error, release or debug do not matter.

OutOfMemoryException is thrown when you don't have enought memory to run
application. Please post the code that you are using.

I am pasting running code below.

class MyClass
{
int[] a = new int[30];
int [,] b = new int[10,20];
public int SomeMethod()
{
return 0;
}
}

class OtherClass
{
MyClass[] cls = null;
public void DoSomething()
{
int a = 3000;
cls = new MyClass[a];
}
}

public class Class1
{
public static void Main()
{
OtherClass other = new OtherClass();
other.DoSomething();
Console.Read();
}
}
 
F

Fernando

First at all thanks for your help.
I wrote the code as an example, so i'm sorry about syntax errors, my
fault :)

In fact, based on the example classes I wrote, I call the class method
'DoSomething()' inside a Windows Form from a button click event handler.
The class object is initialized as a private member of the Form. On
Debug all works as expected, but running the application on Release the
OutOfMemoryException is raised on the following code:

class OtherClass
{
private MyClass[] cls = null;

public void DoSomething()
{
int a = 3000;
cls = new MyClass[a]; -> OutOfMemoryException
}
}

The .Net framework documentation on OutOfMemoryException points me to
check array initialization and declaration, but I think it's fine. There
is any compiler directive which I must use in order to raise array
allocated memory?

Thank you again.

Fernando,

First, If this is C# code you are trying to compile then it will not
compile. It is buggy with small syntex errors.
Second, after fixing those syntex errors this program it should not give you
any error, release or debug do not matter.

OutOfMemoryException is thrown when you don't have enought memory to run
application. Please post the code that you are using.

I am pasting running code below.

class MyClass
{
int[] a = new int[30];
int [,] b = new int[10,20];
public int SomeMethod()
{
return 0;
}
}

class OtherClass
{
MyClass[] cls = null;
public void DoSomething()
{
int a = 3000;
cls = new MyClass[a];
}
}

public class Class1
{
public static void Main()
{
OtherClass other = new OtherClass();
other.DoSomething();
Console.Read();
}
}



Hi, I'm programming on Visual C# Express Beta 2 and I have the following
code:

class MyClass
{
int[] a = new int[30]
int [,] b = new int[10,20]

public int SomeMethod()
}

class OtherClass
{
MyClass[] cls = null;

public void DoSomething()
{
int a = 3000;
cls = new MyClass[a];
}
}

class program
{
OtherClass other = new OtherClass();

public int main()
{
other.DoSomething()
}
}

When running on Debug , this code works as expected, but on Release I get
an
OutOfMemoryException allocatting the array on "cls = new MyClass[a]" when
calling "DoSomething"

Can someone help me to solve it?

Thanks in advance

Fernando
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top