473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

System.OutOfMemoryException when showing form

Baz
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a very
trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a
little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables
so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent.
Here is the code which does that:

Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frmCountry As New frmCountry

frmCountry.MdiParent = Me
frmCountry.Show()

End Sub

BUT, one of the first things frmCountry does is to grab itself a middle-tier
object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned
above i.e. it needs to refer to the two global variables. Hence, I have a
Form Load event procedure as follows (where cfrMain is a user control I have
created which has the combo boxes on it):

Private Sub frmCountry_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSource = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have adopted
here, or any specifics in these code snippets (I am, after all, trying to
learn). However, the particular problem I have is that the statement
frmCountry.Show() throws a System.OutOfMemoryException error. HOWEVER, and
here's the weird bit, if I comment out the following two statements in
frmCountry_Load, then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global variables
with literals e.g.

.UserName = "myuser"
.Password = "mypassword"

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error?
And what can I do about it? And should I give up on the mdi application (a
trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz


Nov 20 '05 #1
4 4149
Hi Baz

The first thing I noticed was that you define a variable with the same name
as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This
may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co.uk> wrote in message
news:10****************@lotis.uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a very trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a
little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables
so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent.
Here is the code which does that:

Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frmCountry As New frmCountry

frmCountry.MdiParent = Me
frmCountry.Show()

End Sub

BUT, one of the first things frmCountry does is to grab itself a middle-tier object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned
above i.e. it needs to refer to the two global variables. Hence, I have a
Form Load event procedure as follows (where cfrMain is a user control I have created which has the combo boxes on it):

Private Sub frmCountry_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSource = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have adopted here, or any specifics in these code snippets (I am, after all, trying to
learn). However, the particular problem I have is that the statement
frmCountry.Show() throws a System.OutOfMemoryException error. HOWEVER, and here's the weird bit, if I comment out the following two statements in
frmCountry_Load, then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global variables with literals e.g.

.UserName = "myuser"
.Password = "mypassword"

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error?
And what can I do about it? And should I give up on the mdi application (a trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz



Nov 20 '05 #2
Hi Baz

The first thing I noticed was that you define a variable with the same name
as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This
may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co.uk> wrote in message
news:10****************@lotis.uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a very trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a
little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables
so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent.
Here is the code which does that:

Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frmCountry As New frmCountry

frmCountry.MdiParent = Me
frmCountry.Show()

End Sub

BUT, one of the first things frmCountry does is to grab itself a middle-tier object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned
above i.e. it needs to refer to the two global variables. Hence, I have a
Form Load event procedure as follows (where cfrMain is a user control I have created which has the combo boxes on it):

Private Sub frmCountry_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSource = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have adopted here, or any specifics in these code snippets (I am, after all, trying to
learn). However, the particular problem I have is that the statement
frmCountry.Show() throws a System.OutOfMemoryException error. HOWEVER, and here's the weird bit, if I comment out the following two statements in
frmCountry_Load, then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global variables with literals e.g.

.UserName = "myuser"
.Password = "mypassword"

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error?
And what can I do about it? And should I give up on the mdi application (a trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz



Nov 20 '05 #3
Baz
Thx for the reply Charles. Good point about the naming.

I have changed the design so that UserName and Password, instead of being
properties of the middle tier object, are instead arguments of it's methods.
This involved moving the code that references the global variables, so that
it is now done by the user control, cfrMain, rather than in the Load event
of the form. It still gets done when the form loads, but it's a couple of
calls further down the stack, as it were. And...the problem went away.

Seems to be (yet another) bug in .Net. A few days ago I wasted a couple of
hours discovering the unreliability of setting the SelectedIndex for a bound
combo box to -1. Is programming in VB.Net always this frustrating?

Baz

"Charles Law" <bl***@nowhere.com> wrote in message
news:uP**************@TK2MSFTNGP12.phx.gbl...
Hi Baz

The first thing I noticed was that you define a variable with the same name as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co.uk> wrote in message
news:10****************@lotis.uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a

very
trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent. Here is the code which does that:

Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frmCountry As New frmCountry

frmCountry.MdiParent = Me
frmCountry.Show()

End Sub

BUT, one of the first things frmCountry does is to grab itself a

middle-tier
object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned above i.e. it needs to refer to the two global variables. Hence, I have a Form Load event procedure as follows (where cfrMain is a user control I

have
created which has the combo boxes on it):

Private Sub frmCountry_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSource = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have

adopted
here, or any specifics in these code snippets (I am, after all, trying to learn). However, the particular problem I have is that the statement
frmCountry.Show() throws a System.OutOfMemoryException error. HOWEVER,

and
here's the weird bit, if I comment out the following two statements in
frmCountry_Load, then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global

variables
with literals e.g.

.UserName = "myuser"
.Password = "mypassword"

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error? And what can I do about it? And should I give up on the mdi application

(a
trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz




Nov 20 '05 #4
Baz
Thx for the reply Charles. Good point about the naming.

I have changed the design so that UserName and Password, instead of being
properties of the middle tier object, are instead arguments of it's methods.
This involved moving the code that references the global variables, so that
it is now done by the user control, cfrMain, rather than in the Load event
of the form. It still gets done when the form loads, but it's a couple of
calls further down the stack, as it were. And...the problem went away.

Seems to be (yet another) bug in .Net. A few days ago I wasted a couple of
hours discovering the unreliability of setting the SelectedIndex for a bound
combo box to -1. Is programming in VB.Net always this frustrating?

Baz

"Charles Law" <bl***@nowhere.com> wrote in message
news:uP**************@TK2MSFTNGP12.phx.gbl...
Hi Baz

The first thing I noticed was that you define a variable with the same name as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co.uk> wrote in message
news:10****************@lotis.uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a

very
trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent. Here is the code which does that:

Private Sub mnuCountries_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuCountries.Click

Dim frmCountry As New frmCountry

frmCountry.MdiParent = Me
frmCountry.Show()

End Sub

BUT, one of the first things frmCountry does is to grab itself a

middle-tier
object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned above i.e. it needs to refer to the two global variables. Hence, I have a Form Load event procedure as follows (where cfrMain is a user control I

have
created which has the combo boxes on it):

Private Sub frmCountry_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSource = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have

adopted
here, or any specifics in these code snippets (I am, after all, trying to learn). However, the particular problem I have is that the statement
frmCountry.Show() throws a System.OutOfMemoryException error. HOWEVER,

and
here's the weird bit, if I comment out the following two statements in
frmCountry_Load, then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global

variables
with literals e.g.

.UserName = "myuser"
.Password = "mypassword"

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error? And what can I do about it? And should I give up on the mdi application

(a
trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz




Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: solomon | last post by:
Hi, I have installed VS.Net(Ver:7.0.9466) & .Net_Frameword_1.0 (Ver: 1.0.3705). Until recently, I could develop and run applications using the IDE. A couple of days ago, I downloaded a sample...
1
by: king solomon | last post by:
Hi, I have installed VS.Net(Ver:7.0.9466) & .Net_Frameword_1.0 (Ver: 1.0.3705). Until recently, I could develop and run applications using the VS.IDE. A couple of days ago, I downloaded a...
0
by: Per Bergland | last post by:
After many woes, I finally managed to get a stack dump of my System Service (written in C#) that insists on crashing when launched at system boot time (see below on how to get this dump - I...
1
by: Ripul Handa | last post by:
Hi We are running IIS 5.0 cluster with cisco local director. We are running a website on 2 webservers and I have been observing that from past few days we have are getting this error message of...
1
by: SMG - Idealake | last post by:
Hi all, I am getting following error on my error, what could be the reason? Exception of type System.OutOfMemoryException was thrown. Description: An unhandled exception occurred during the...
2
by: Baz | last post by:
Hi. I'm new to this VB.Net mullarkey, and I must say it is proving to be a very trying experience. Here is the latest in a long line of problems: The Scenario ========= I am building an...
1
by: Ashkan Daie | last post by:
Hi All, When trying to install a performance counter via InstallUtil I get the following exception: Creating performance counter category Enterprise Library Caching. An exception occurred...
2
by: ari | last post by:
I have a small form that comprises a toolbar, a treeview and a status bar. Everything was working fine until I decided to add a new button to the toolbar - and I decided for appearances sake to...
8
by: =?Utf-8?B?UGlnZ3k=?= | last post by:
Hi to all, I am getting this System.OutOfMemoryException calling the Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method. The type of <streamis...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.