Solved

Visual basic memory usage and unloading forms

Posted on 2004-03-27
10
305 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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