Solved

Visual basic memory usage and unloading forms

Posted on 2004-03-27
10
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

739 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