Memory By Adding Some GC.COLLECT() Calls

Dec 10, 2009

I have a windows app (2.0 framework) that's about 860k in size, just a small db app with a couple of data entry screens and a few reports (Cystal) I noticed that when the app starts the mem usage according to task manager is ~11,000k viewing just one report jumps the mem usage to 56,000k. i thought i could reclaim some of that memory by adding some GC.COLLECT() callls, but no luck. Mem usage stays the same in task manager.

So I made an even smaller test app with two forms....Form1 has two buttons , button1 Opens Form2, and button 2 calls GC.COLLECT()

From 2 contains a datagridview and 1 button. The form load for form2 executes the fill for the dataset that populates the datagridview and the button on Form 2 closes the form.

Here's the code for each form....

CODE:

No matter what I've tried so far I cannot seem to reclaim mem that gets used.

View 3 Replies


ADVERTISEMENT

VS 2008 - GC.Collect: Memory Vs Performance?

Jan 29, 2011

I have an application (i've been working on for a long time) that has many tabs and controls and quite a few components And a good deal of design code. And a list box that has around 100k items (i had to put a loader to pass the 3-4 seconds while its loading to prevent it from not-responding)I had a few Gc.collect calls in specific places (mostly after many items are added or removed). When my application loads, i call GC.collect only once at the end of the load. The program consumes around 35K memory by the time its loaded. However, i decided to mess around abit (don't worry i made backups)First i started putting gc.collect in some random places, and to my surprise the memory upon loading was observably decreasing. Then I went ahead and put a macro that puts GC.Collect before every End Sub, Exit Function, Exit Sub, and Return value, there is. Basically every block in my application had atleat one GC.Collect.
I fixed some 6 or 7 silly replace errors and compiled. When the program launched, the memory used at the end of launch was 21K!

At first glance that seemed great, but then i realized switching between tabs was VERY glitchy. and adding new lists took around 10x more time than usual (the loader stayed on for around 20 seconds!) And even though the memory looked good, the program was useless like this.Then i decided to mess around differently. I removed GC.Collect from the entire solution. It was no longer called even once.At first glance, when i launched the app it consumed just under 60K memory. That seemed terrible. However i realized something: even though my program in that state showed on taskmanager that it was consuming alot more memory than usual, it seemed like it was lighter than ever! Switching tabs was faster than before, especially every time i go to the tab that has the listbox control with 100k items. Loading items took around 3-4 seconds, but there was no stutter when the list finished loading whereas before it had an evident 0.3s stutter after the items were added.

This was all surprising to me because i thought GC.Collect was first of all, something that it doesnt matter where or how many times you call it. I thought it was just something that should be called at the end of work and i didnt think it would matter if it was called during work.Second of all, i thought GC.Collect only affected resources that are inaccessible, or resources my program is done with. How come the application feels faster when i don't call it?Third of all, i thought the VB CLR does most of the memory cleaning for me, and that GC.Collect was somewhat of a redundant command. It didn't seem so redundant to me at all considering the difference between using it heavily and not using it at all was around 38K in memory usage!

So i guess my questions are:
1) Do I need to call GC.Collect? WhereWhen do i call it?2) Why does calling it affect performance? And where does one draw the line between that memory stat on taskmanager and the program's performance?3) I also decided to run a small test. Why does a blank vb form application require 10K memory? How accurate is that stat shown on the task manager?

View 3 Replies

Reduce The Memory Usage Forcing To Garbage Collector To Collect With The Method?

May 1, 2012

I have a problem with an application, in this case I have a windows services. its function is generate reports depending of demand of our users.In some cases the memory usage of my windows services is to 2 gb of RAM. I disposed all objects that my application use . but the memory usage doesn't low.I tried to reduce the memory usage forcing to garbage collector to Collect with the method "GC.Collect"but it's not recommend because uses many time of CPU.Surfing on the internet I found a method named "SetProcessWorkingSetSize" that free memory usage correctly. http:[url]....but some cases my windows services named sapdkadm_procesoestandarejecucion.exe has some error message in event viewer is the next:

Faulting application sapdkadm_procesoestandarejecucion.exe, version 1.0.0.0, stamp 4f908fef, faulting module kernel32.dll, version 5.2.3790.4480, stamp 49c51cdd, debug? 0, fault address 0x0000000000027ded.

The real problem is that when this happens my windows services restart

View 3 Replies

Is There Any Real Advantage To Run A GC.collect After That Our Application Has Used A Large Quantity Of Memory Or It Is Just A Psychological Factor?

Jun 29, 2011

is there any real advantage to run a GC.collect after that our application has used a large quantity of memory or it is just a psychological factor?

View 17 Replies

Generating A Rather Large Memory Leak - Every 5 Seconds It Calls CheckSettings

Sep 19, 2009

I seem to be having some issues with my code here. The sub "CheckSettings" is actually run off of a system timer, so that every 5 seconds it calls CheckSettings (actually, i set it to every 1 second for debugging, so i can see the leak a little more clearly by monitoring the process). CheckSettings basically checks to ensure there isn't already an instance of the thread running, and if there is, it checks to ensure that the instance has completed running ... once it has the go ahead, it creates a new thread and runs again.

code:

This code is creating a very large memory leak. After a few minutes of running, my application goes from a memory footprint of about 45,000 K to about 1,000,000 K. Quite the leak. I read some articles on the managed versus unmanaged memory etc, and I was careful to free the objects etc.

View 3 Replies

Win32 API - Equivalent To Making System Calls Abd And Library Calls In UNIX?

May 8, 2010

What the Win32 API is? I have looked around but no where really outlines what it is. Is it basically a set of procedures, outlined by Microsoft for programmers in order to get services from the operating system? In essence is it the equivalent to making system calls abd and library calls in UNIX? And yes I now Windows makes library calls too.

View 2 Replies

Replacing DbTransaction Calls With Calls To TransactionScope?

Mar 4, 2010

I have been using DBTransaction for my current projects that access a single database. However, I read some documentation on TransactionScope and was wondering in which scenario would using TransactionScope be better? Or should I be replacing DbTransaction calls with calls to TransactionScope?

View 2 Replies

When And Why Need To Use GC.Collect()

Jan 24, 2012

My application waits for the user to click twice to draw a rectangle on an image, and use the rectangle to create a clone and save it. Then it restarts with the next rectangle. When I work on a large image (10800x7236) after a few cycles I get an out of memory error. but I still don't understand what's going on, and I would appreciate if some expert out there clarified why it didn't work before and it works now. This is the snippet executed after the user clicks twice, and fails after 5-6 cycles:

[Code]....

View 1 Replies

Collect A Random First And Last Name?

Mar 11, 2012

I currently have code that creates and inserts ~175,000 names into a table.

What is the quickest way to collect a random first and last name? So far I have tried, Reading from two text files where every name is one line it takes ~2:30 minutes Reading from a table with [first][last] columns takes ~4 minutes

View 4 Replies

Collect Before And After Values From A Dataset?

Sep 12, 2011

I have a multi-user app which consists of a Windows form (VS2008), and a SQL Express 2008 database. I'm already detecting if the dataset has changed before the user closes the form so I can prompt them to save their changes. What I'd like to do is to capture the changes they've made, and write them to a database table so that users can track all changes made to each record on the DB.What is the best way to grab hold of the data changes before they're written back to the DB and also grab the original records?

View 1 Replies

SQL Query Data Collect?

Nov 18, 2009

I have a SQL server table that has a list of Usernames and a list of points ranging from 1 to 10,000.I want to display the number of points in my VB.NET program from the username given. For example, if I type in "john" in the first box the program will give me a message box saying whatever amount of points "john" has. I'm not really sure about

This is the Table Structure:
Usernames Points
-----------------------------

[code].....

View 1 Replies

Loading An Image From A Jpeg That Exists In Memory (but Not On Disk) Using Direct Memory Access

Nov 5, 2009

In VB 2005, I am calling a C++ DLL function that returns the address in memory and size in bytes of a jpeg image. How can I load that jpeg image directly from memory into a picture box in my VB form? I cannot afford to save it to disk first.

View 10 Replies

Attempted To Read Or Write Protected Memory / Often An Indication That Other Memory Is Corrupt

May 22, 2007

Im getting a problem with one of my programs I have made in visual basic.NET where it gives me a memory error when i debug the program in the IDE. the exact error is this: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt". My program basically has a few forms with text fields on that get their text values from an access database on the same hard drive. Im wondering if im doing something wrong because my program just seems to eat up memory whenever it does anything. For example I have one form that has a combobox on it and when you change the drop down list selection it retreives a few strings from the database and puts them into the relevant text boxes, if you keep changing the selection then the memory usage (in task manager) just keeps going up and up. occasionally I get the error mentioned above when debugging but in my built version of the program it throws an exception everytime the memory usage gets past 49K.

Also I noticed when debugging in the "immediate window" frame I get the following message often:A first chance exception of type 'System. Invalid OperationException' occurred in System.Data.dll...Do I need to somehow be "releasing" the memory that is used to gather data once it becomes redundant?

View 12 Replies

Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt

Nov 24, 2011

I am using the following code

This error occurs :

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Public Class FormRegEnumValue

[CODE]......................

View 2 Replies

Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt?

Feb 1, 2009

QuoteSystem.AccessViolationException was unhandled Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Source="System.Windows.Forms"

Im designing a web browser and i continue to receive this error after going to about 3 websites it crashes with that error.

View 6 Replies

Necessary To Detach Event Handlers To Ensure That Memory Is Cleaned Up And That There Are Not Memory Leaks?

Jan 20, 2010

I have a BackgroundWorker object that I instantiated to perform a DB process on a background thread ansynchronously. I have event handlers for DoWork and RunWorkerCompleted. I can tell that the BackgroundWorker is disposing of itself because I added a message box into the Disposed event handler.Is it necessary to detach the event handlers to ensure that the memory is cleaned up and that there are not memory leaks?

View 1 Replies

Thread And Memory Leaks - Memory Usage Jumps About 1000k And It Never Goes Back Down

Apr 17, 2011

I've noticed that every time I start a new thread in my program, the memory usage jumps about 1000k and it never goes back down. I have ensured that the thread is no longer running, and only one instance of my worker thread is ever running at a time. I am using ThreadPool.QueueUserWorkItem and ASyncOperation to get stuff done. The program starts using a Sub Main in a module that uses STAThread; I read that using STAThread instead of MTAThread makes it impossible for the Garbage Collector to get in and consider objects for garbage collection. However, when I change the STAThread to an MTAThread, the WebBrowser control in my frmMain cannot be instantiated.

I get this exception:

Code: An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

Additional information: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment. I do threading with the WebBrowser control, so will using MTAThread fix my problem? If so, how should I partition my code so that the WebBrowser control won't be affected by the above exception? I call the thread repeatedly with a timer (although only one instance ever runs at a time), and my program's memory usage starts at about 5000k and can jump to 300,000k+ depending on many times the thread needs to be called.

View 6 Replies

2008 Express Edition: Attempted To Read Or Write Protected Memory, This Is Often An Indication That Other Memory Is Corrupt?

May 27, 2009

I cannot use Visual Basic 2008 at all. When I go to "new project" and choose "Windows Form Application" I get this error.I have tried multiple uninstall/reinstall with no result.A microsoft reply to this suggested that I needed: " .NET Framework 2.0 Service Pack 1 " I checked, and I did not have the .netframework 2.0 service Pack 1.
When I tried to download and install the above from Microsoft.com, the istaller said that "it was not allowsed" and I was not able to install the service pack 1.

I tried Uninstalling net framework 3.5, 3.0, 2.0 and then reinstalling .netframework 2.0 sevice pack 1; then reinstalling Visual basic 2008 express edition. At the reinstall of Visual basic 2008, .netframework 2.0 sevice pack 1 is unistalled by .net framework service pack 2.When I check the foruims for simiar problems, the formus are mostly for Visual basic 5.0, or other programs that I do not have.

Here is the programs I have installed:

Operating system: Windows XP
Microsoft .net framework 1.1
Microsoft .NET framwork 1.1 Hotfix(KB928366)
Microsoft .Net Framework 2.0 Service Pack 2

[code]....

All the security updates and hotfixes for Widows XP.

View 4 Replies

DirectoryEntry Memory Leak - Gets A Out Of Memory Error In The Last Catch Statement?

Jan 11, 2012

The follow code can be called about 6K times on the server it is run on then gets a out of memory error in the last catch statement. I don't see what is wrong with the code, it works well up until the out of memory..

Public Function AddUserToGroup(ByVal sSamAccountName As String, ByVal sGroupName As String) As Boolean
Try
Dim returnStatus As Boolean = True[code]......

View 3 Replies

Read Or Write Protected Memory Often An Indication That Other Memory Is Corrupt?

Feb 9, 2011

I have two forms, Form1 and Form2. Form2 has a button to show OpenFileDialog. I call Form2 from Form1 by a button. My startUp Form is Form1. When i start debugging, i press my Form1's button to show my Form2, it shows, but when i click On Form2's Button to show OpenFileDialog it is giving me exception that

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

When i set my startup Form to Form2 and click Form2's Button to show OpenFileDialog then it shows!

View 13 Replies

Asp.net - Retrieve Collect Of Object In Listcollection?

Jul 27, 2011

I have a class orderItem it is a parent of Product and service class Im adding product or services in a listcollection. How can I cast service or product for retrieving orderitem?

Public MustInherit Class OrderItem
Private m_enuItemType As TypeOfItem = TypeOfItem.None
Private m_strUserID As String = ""

[Code]....

View 1 Replies

Collect All Data From Db To Show In Textbox?

Jun 12, 2010

I have 4 textboxs in my new form. and each of them, i want the data from the db show in the txtbox.[code]...

View 1 Replies

Collect Two Sets Of Data From Two Different Databases

Feb 5, 2009

I collect two sets of data from two different databases, This data is now in two collections. I then join/append the one collection to the other and then put it in to a list view.I really would like to order this list view by the first column without the click event.To make this even harder the First column contains Data that is DateTime and i have found that it orders the items by the day number and not the months or years or time.I have found one way but it then cause's me further agony when doing some checks upon the data within the listview later in my code. This answer is to rearrange the format to "yyyy-MM-dd HH:mm:SS" then using the listview.sorting = sortorder.

View 7 Replies

Create An Application That Collect Data From The Rs-232?

Mar 11, 2010

i want to create an application that collect data from the rs-232.Someone have a code example with multi rs-232 in thread .I have one pc that have mapping virtual com.

View 1 Replies

Go Back And Collect Missing Hours?

Dec 31, 2010

What I need to do is have my application check to see if the last hour that was inserted into the database table is equal to the current hour minus 1 hour when it runs. If it is not equal to the current hour -1 then it needs to go back and download the missing data automatically.

The hours go from 1 to 24 with midnight being the 24th hour as you'll see in my code. My problem is I don't know how to code what I'm trying to do.

Here is the current code:

Private Sub HourDownload()
DeleteFileHour()
If OneHour("C:abcd.pfx", "******") = True Then

[Code]....

View 11 Replies

How To Collect Readings Done After Port Opened

Feb 1, 2011

I'm using the .NET SerialPort class to communicate with gauges. Every time a button on a gauge is pressed a reading value is sent over port. The problem I have is that if the gauge button is pressed while the program is off then when the program starts it fires the data received event for that existing data. I don't want this behavior -- I only want to collect readings done after the port is opened.

port = New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)
port.Open()
port.DtrEnable = True
System.Threading.Thread.Sleep(100)
port.ReadExisting()
AddHandler port.DataReceived, AddressOf PortDataReceived

If I don't have the Thread.Sleep then the DataReceived event is fired for the previous gauge data. I'm guessing this is because the ReadExisting doesn't block and so when its called immediately after an open it just reads nothing. So if you call 'port.BytesToRead()' immediately after open its zero. If you call it 100ms after open its non-zero. I guess this makes sense -- it takes time after open to read the existing data. Another option is to call read and set the read timeout but that seems no different than Thread.Sleep except you have to catch an exception...

View 1 Replies

Phrasing XML File And Loading Into A Collect?

Aug 11, 2010

I am running into an issue with phrasing the following XML. I need to load the content into a object that is outline in the second code block. I am looking for all items to be Property flags within the Object.

<MigrationType>
<MigrationOption id="1">
<NAME>Project Configuration</NAME>
<DISPLAY>TRUE</DISPLAY>
<PAGE id="1">RequiredItems</PAGE>

[Code]...

View 6 Replies

Collect A Sequence Of Events In A Variable Of Some Sort

Jul 31, 2011

In my program; I need to collect a sequence of events in a variable of some sort. Each time the Sub is initiated, it should add one random event to the sequence (so that it gets longer each time) and then run through the sequence.This is rather difficult to express.What I'm trying to do, is create a Simon Says game with the four buttons.After the sequence goes through blinking the buttons, the program must then be able to capture the sequence of button presses by the user and match that to the sequence that the program ran.So, I need to be able to keep track of two sequences in a variable. Arrays?

View 3 Replies

Collect All Parameters From Reports And Populate SQL Table

Apr 20, 2012

I have a table on my SQL DB call ReportList which is a list of report. I need to go through that list and interrogate the reportserver, eport by report, to populate a table called ReportParameters. The ReportParameters table has a column for ReportOwnerID which needs to contains the ReportID value of the corresponding (owner) report as listed in the ReportList table.

It needs to work so:- I have a listbox of the reports as per REportList and a GridView that list all the parameters (uniquely - most of the parameters are common to many reports) the idea being that the parameters get set once and the report can be kicked off by selecting them in the ReportList CheckListBox and clicking on Execute. I would like it that as I click on a particular report in the ListView, the relevant parameters in the Gridview get a green background and those that do not apply are red. The leftmost column in the gridview contains tha Parameter NAME (not editable) and the next column must be editable to populate the value.

Done so far: I have tried on clicking the Execute button, to build a parameters string in a testbox and call that with the Javascript OpenReportWin() function when I open the report in a new window. This works fine, but my biggest issue it interrogating the reportserver reports to get back a list of parameters and dooping them into a table. I have tried to use a hidden DataGrid bound to a ds onto the reportParamaters table.

I have tried to populate it using a datalist but I cannot get the hang of these thionsg and its looking messy. Their must be a simple clean way of getting the .GetParameters resultset back from the report server and populating the table without having to create a reportviewer object and cycling through the list of reports - it then has to render each report before you can get that list out.

View 1 Replies

Collect Data From CSV Files And Paste It In One Xls File?

May 10, 2012

I get a problem with my program. My program should do :

-Explore folders from a main folder (LOGS)

-See if there are csv files

-Copy the data from CSV (all informations are on the first column)

-Paste it in one xls file (with a sheet for every csv)[code]...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved