Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of jennajdev
jennajdev

Memory Error crashing VB.NET application
A program I am developping in VB.NET is suffering from an inconsistent memory related crash, and I have decided to sign up for an Experts Exchange account in the hopes that someone can offer some assistance with this frustrating issue.

This is a program that runs for long periods of time.  Windows error reporting is turned off, yet this error box still appears.

I will give a brief rundown of the code structure, and should more information be necessary I will be as specific as is required.

frmMain launches 11 threads.  Each thread begins a timer, and at set intervals launches yet another thread.  The purpose of these timer-launched threads is to launch yet more threads that will each perform a "scan" of sorts against a list of machines on the local network.  One specific scanning thread which runs far more often then all the others is the problem thread.  It will run fine for a while, then I hit a memory error and the thread dies.  All 10 other threads remain functional, as I am tracking the output of each.  

I am not able to reproduce the issue.  I have reports of it crashing within an hour of being started, yet sometimes it will run for days with no issues, and sometimes it will run with no issues period.  All of my code is inside try/catch blocks.  My application will remain open, all other threads still running fine until OK is pressed on the error message, which causes the application to shut down (sometimes!!!).  The error messages sometimes repeat and stack on top of each other.

Any assistance would be greatly appreciated!
error-message.JPG

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Aaron JabamaniAaron Jabamani🇬🇧

1. Do you have logs created in critical codes, so that we can see which/where the error is generated ?
2. At the time of crash, can u deceide how many threads were running totally ? so that u can do a stress test of ur applicatio which might lead u to re-produce the same.
3. Does each thread has it local data created?if yes, try to pin the data to that GC might not move them across while clean up.

Avatar of jennajdevjennajdev

ASKER

Apeter:

Do i have logs created:  I have a ton of output being pritned to the screen which i can view after a crash.  The output is never exactly the same, but the code always breaks in generally the same area.  However, there is nothing there that I can directly attribute to crashing my app.  Unless VB is screwing up garbage collection somehow, which I find hard to believe.

How many threads were running:  No, I dont log this information.  However, the number of threads running at one time is tightly controlled, and even manually running the maximum number of threads does not reproduce the issue.  Normal program runtime would not even be running the max anyways.  

Can you please clarify your #3?  I am passing a struct into my scanning threads.  Each thread does collect a fair bit of data itself using ManagementObjects (WMI), but since I have been attempting to fix this issue I have even added manual garbage collection on pretty much anything that implements a dispose method.

Pinning is mostly used when u interact with unmanged code, looks like it is not with your case.

Hope below link helps u on memory leak.
http://blogs.msdn.com/tess/archive/2006/01/23/net-memory-leak-case-study-the-event-handlers-that-made-the-memory-baloon.aspx

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Thanks for the link.  Interesting reading.  Unfortunately his error is easily reproducable with the ability to be on the spot to debug.

My application crashes sporadically.  On top of that, it is crashing on computers that do not have Visual Studio, nor am I informed exactly when it crashes.  How can I trap "bad memory" information to assist in debugging this issue?

Thanks again

What is a "Windows Forms thread" ?  I am hoping here that since my try/catch blocks don't seem to register any issues before a crash that adding this handler will allow me to find the location of the memory-leak-causing code by trapping it?  Can you please confirm?

"You can change whether this callback is used for unhandled Windows Forms thread exceptions by setting SetUnhandledExceptionMode.To catch exceptions that occur in threads not created and owned by Windows Forms, use the UnhandledException event handler. "

Since the error messages I see are clearly labelled with the name of the .exe, is this necessary?

And one last quick question from my brief read through:

"It sets SetUnhandledExceptionMode so that all exceptions are handled by the application, regardless of the settings in the application's user configuration file"

Im assuming this refers to the app.config file I have in my project.  Is it possible to modify this file to force my application to perhaps write some useful information regarding the crash into the event logs?

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Aaron JabamaniAaron Jabamani🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

I have created a new vb.NET console application.

I added the UI and non-UI error handler functions, and a call to Application.Run(frmMain)

I added my original scanner into the new project and the console application now launches it.

No errors as of yet, I will report back when I know more.
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.