Solved

Visual basic memory usage and unloading forms

Posted on 2004-03-27
10
312 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
 
LVL 18

Expert Comment

by:Sethi
ID: 10695213
Hmm...then there is nothing I can think of.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now