Solved

Visual basic memory usage and unloading forms

Posted on 2004-03-27
10
315 Views
Last Modified: 2013-11-25
Hi everyone

I'm working in VB6.0, and  have two forms, the first one has a button and the second a crystal reports 8.5 viewer. Clicking a button one the first form launches the second one which displays a crystal report.

Using the windows task manager I'm monitoring the memory use of the compiled application and when it starts the mem usage is around 1,900K and then when I click the button to launch the second form it shoots up to about 14,000K, but when I closed down the second form it stays at 12,000K. Surely when that second form is closed it should drop down to a level similar to its starting point?

Am I missing something here? Any help would be greatful. Sourcecode below.


Form1 > references > Crystal Report Viewer control & Crystal Reports Activex 8.5 Designer run time library

Form 1
******
Private Sub Command1_Click()

Load Form2

Set crystal = New CRAXDRT.Application
Set Report = crystal.OpenReport(App.Path & "\" & "test.rpt")


Form2.CRViewer1.ReportSource = Report
Form2.CRViewer1.ViewReport
Form2.Visible = True

End Sub

Form2
*****

Private Sub Form_Unload(Cancel As Integer)

Set crystal = Nothing

Set Report = Nothing

End Sub
0
Comment
Question by:supermeerkat
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 10695087
Also set the form to nothing...Example Set Form2 = Nothing after unloading Form2...
0
 

Author Comment

by:supermeerkat
ID: 10695137
Tried that, but still no joy. By stepping through the app i've determined that the lines

Set crystal = New CRAXDRT.Application
Set Report = crystal.OpenReport(App.Path & "\" & "test.rpt")

cause the memory usage to shoot up and set them both to nothing causes memory usage to drop by about 2 megs
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10695203
VB6 doesn't really unload the form until the application has completely exited.  This is so that subsequent reloading of forms is faster.

Idle_Mind
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 18

Expert Comment

by:Sethi
ID: 10695213
Hmm...then there is nothing I can think of.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10695235
supermeerkatj,

Can you determine if the problem is really VB6 or Crystal Reports?

Is all of the memory released once the application has completely exited?  It may take a couple seconds to see the release.

If the memory is not released after the app exits, then the Crystal Reports objects are the likely culprit.

I've never used Crystal Reports before.  Does it have a Dispose() method or anything similar that is supposed to be called once you are done with it?

Idle_Mind
0
 

Author Comment

by:supermeerkat
ID: 10695586
After about 3 more hours of searching I've found out that its a crystal reports issue, not visual basic one. Sorry about that.

Thanks for your help and suggestions guys.
0
 
LVL 2

Expert Comment

by:jasonholland
ID: 10695943
Here you go boss, this should answer your question.

You must not have any variables, controls, or references to the form otherwise the form remains in memory.
This includes if you loaded the form from the .show method or by referencing an object on the form. It will
remain in memory.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconlifecycleofvisualbasicforms.asp

0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11439534
PAQed, with points refunded (125)

modulo
Community Support Moderator
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question