Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Visual basic memory usage and unloading forms

Posted on 2004-03-27
10
Medium Priority
?
367 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 86

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

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

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

971 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