Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / December 2007



Tip: Looking for answers? Try searching our database.

Garbage collect (or what?)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave D-C - 01 Dec 2007 16:55 GMT
Hello,

Using XL97VBA/WIN98 and SendKeys and Appactivate and
Shell, I'm successfully able to make thumbnails with either
Paint or Photoshop Elements.  But, after processing 100 or so
images, it seems the system gets bogged down or
something, and Paint gets "out of memory" errors and
Photoshop also gets a problem, I don't know what.

I've run "Accesories/System Monotor" and know that
memory allocation is high and swap usage is high.

Q's:
1)  Can I call some kind of "Garbage Collect" API
every once in awhile to keep things cleaner?
2)  Can I call some kind of "Memory Usage" or
"Swap Usage" API and maybe terminate/re-shell
the program based on that?

I haven't tried to terminate/re-shell on a regular basis --
maybe that's a solution.

TIA, D-C Dave
mr_unreliable - 02 Dec 2007 18:58 GMT
hi Dave,

It sounds like all those graphic images are piling up
in memory, and then forcing "virtualization" (or expanding
real memory by creating virtual memory -- your disk
swapfile).

Are you processing them all-at-once(?), i.e., as in making
up a page of thumbnails?  If so, then the application is
loading your graphic images in memory, but is not having
any opportunity to release the memory.  And, there is no
garbage collection if the graphic image memory doesn't
get released.

If that is the case, I would suggest processing the images
one-at-a-time, save the thumbnail to disk, and then close
your app.  That way, the app (should) release the memory
allocated to your graphic.  Finally, re-assemble your
thumbnails.

In general, my impression is that "garbage collection" is
not invoked until the system runs out of memory.  It will
then start releasing blocks or memory as needed that have
been de-allocated, the oldest one first.  If there are no
de-allocated blocks, then it will start swapping out memory
to the swap file.  Perhaps there are more knowledgeable folks
here who can provide a more accurate and precise description
of "garbage collection".

However, my impression from what you said is that when your
system starts "thrashing" that it is not "garbage collection",
rather it is the failure to release memory that is the
problem.

cheers, jw

> Hello,
>
[quoted text clipped - 19 lines]
>
> TIA, D-C Dave
Dave D-C - 02 Dec 2007 19:27 GMT
Thanks for your response.  I missed making an important point:
>Are you processing them all-at-once(?)
No, I am doing them one at a time and saving to disk, so
only one is in memory at any time.

I have many DoEvents sprinkled about in my code.
1)  I will try a second or so of DoEvents (or Sleep?)
in between each image (or 10 images).
2)  I will try terminating and re-shelling the program
in between each image (or 10 images).

Thanks again, Dave D-C

>hi Dave,
>
[quoted text clipped - 55 lines]
>>
>> TIA, D-C Dave
Michael C - 02 Dec 2007 23:20 GMT
> Thanks for your response.  I missed making an important point:
>>Are you processing them all-at-once(?)
[quoted text clipped - 8 lines]
>
> Thanks again, Dave D-C

Why don't you just write some code yourself to resize the images?

Michael
Larry Serflaten - 03 Dec 2007 02:45 GMT
> No, I am doing them one at a time and saving to disk, so
> only one is in memory at any time.
[quoted text clipped - 4 lines]
> 2)  I will try terminating and re-shelling the program
> in between each image (or 10 images).

I agree with MC, you'd get more control over the process by
writting the code yourself than shelling out to other applications.

LFS
Dave D-C - 03 Dec 2007 17:47 GMT
"Michael C" <mike@nospam.com> wrote:
>Why don't you just write some code yourself to resize the images?

>I agree with MC, you'd get more control over the process by
>writting the code yourself than shelling out to other applications.

ARE YOU GUYS SERIOUS!?

OK, seriously, You've inspired me to look at that.
I assume I'll have to do this in VB6 and not XL-VBA (right?).
No problem.  In the past I have called a VB6 routine from VBA
by compiling a routine Sub1 in a class module Class1 in a
ActiveX DLL and doing
Dim ObjPtr as New Class1 ' and then
ObjPtr.Sub1() ' does the job.
But all want is a simple Call Sub1().
But that is a separate issue.

So I'll have an Image in a Form and do a LoadPicture and
something like Image1.Width = w and Image1.Height = h
and then SavePicture (as jpg)?
http://search.microsoft.com/results.aspx?q=savepicture+jpg&qsc0=0&SearchBtn0=Sea
rch&FORM=QBME1&l=1&mkt=en-US&PageType=99


I probably won't be using APIs much.  Where else do you
guys hang around when I have questions on this?

Thanks so much.

mr_unreliable <kindlyReplyToNewsgroup@notmail.com> wrote:
>Here are a couple of tutorials on garbage collection
>   http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx
>   http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx

Thanks again, I'll look at those.  D-C Dave
Larry Serflaten - 03 Dec 2007 21:17 GMT
> "Michael C" <mike@nospam.com> wrote:
> >Why don't you just write some code yourself to resize the images?
[quoted text clipped - 7 lines]
> I assume I'll have to do this in VB6 and not XL-VBA (right?).
> No problem.
<...>
> So I'll have an Image in a Form and do a LoadPicture and
> something like Image1.Width = w and Image1.Height = h
> and then SavePicture (as jpg)?

Getting the image reduced to the size you want is no problem
in VB, its the saving the image as a jpg that is unsupported.

Post the following code into a new form.  It loads an image
on to the form (the form's icon), then scales that image upwards,
prints text on it, and scales it back down again.  You might use
two pictureboxes, one to load the image, and a second to adjust
to the size you want that recieves the scaled down (thumbnail)
version.  From there, you can easily save the image as a BMP
file, but to save as JPG you'll need a bit more code.  Here is
some free code you can add to your project to do that....
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=50065&lngWId=1

Depending on the quality you want for the thumbnails, the
PaintPicture method may work for you if you are not that
picky about quality.  Otherwise, some API work would
allow for even more control, and help to produce better
quality thumbnails.  But, get the basics working first, then
see if you need to tweak it for better performance....

HTH
LFS

Private Sub Form_Load()
 ' Init
 Me.ScaleMode = vbPixels
 Me.AutoRedraw = True
 Me.Font.Bold = True
 Me.Font.Size = 18
 Me.ForeColor = vbRed
 Show
 ' Original
 Me.Picture = Me.Icon
 ' Scale up
 Me.PaintPicture Me.Picture, 0, 40, 128, 128, 0, 0, 32, 32
 ' Print
 Me.PSet (10, 100), Me.Point(10, 100)
 Me.Print "THUMB"
 Me.Picture = Me.Image
 ' Scale down
 Me.PaintPicture Me.Picture, 0, 200, 32, 32, 0, 40, 128, 128
End Sub
mr_unreliable - 03 Dec 2007 16:27 GMT
Here are a couple of tutorials on garbage collection
(past and present):

  http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx
  http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx

O.K., before you flamers start flaming me because the
net framework is mentioned, there is some more general
discussion in those articles which is applicable to
any garbage collection scenario.

As to the op's question, if the graphics are being processed
one-at-a-time, then in all likelihood the original app has
a "memory leak".  I don't especially like that term, but in
plain English it means that some app has failed to release
system resources (such as memory, bitmaps, icons, etc).

You can find various "memory monitors" or "resource monitors"
which will graphically show available memory and/or system
resources being consumed in real time.  If the op brings up
one of these monitors and then runs his job, then he can get
a picture of system memory and/or system resource utilization
and potential "memory leaks".

What to do about it is another matter.  If the original app
is not releasing allocated memory and/or system resources,
then yes -- you are eventually going to come to a grinding
stop.  You can suggest that the app vendor fix his/her app,
or you can "roll-yer-own", i.e., do-it-yourself.

Or, find another app.  There are a number of apps out there
which will create thumbnails for you -- even apps created
by microsoft (who can be relied upon to provide 100% reliable
and error-free code).

cheers, jw

> Hello,
>
[quoted text clipped - 19 lines]
>
> TIA, D-C Dave
Thorsten Albers - 03 Dec 2007 17:12 GMT
mr_unreliable <kindlyReplyToNewsgroup@notmail.com> schrieb im Beitrag
<#59Q0icNIHA.4656@TK2MSFTNGP03.phx.gbl>...
> who can be relied upon to provide 100% reliable and error-free code

Yeah, and our earth is in fact a disk...

Signature

----------------------------------------------------------------------
THORSTEN ALBERS                       Universität Freiburg
                                               albers@
                                                      uni-freiburg.de
----------------------------------------------------------------------

Steve Easton - 04 Dec 2007 14:42 GMT
Save yourself a lot of hassle and use the free IrfanView:
www.irfanview.com
It will batch process 100 thumbnails in about the time it took you to
read this.
Signature


Steve Easton

> Hello,
>
[quoted text clipped - 19 lines]
>
> TIA, D-C Dave
Dave D-C - 08 Dec 2007 20:23 GMT
Thanks for the recommendation.  I'm now using it.
But not to make my thumbnails for my application.
It will "Save selected thumbs as single images" at various
sizes, but they are square and not exactly what I want.
But I'll look more at irfanview as well as making my
own [thumbnails].  

>Save yourself a lot of hassle and use the free IrfanView:
>www.irfanview.com
>It will batch process 100 thumbnails in about the time it took you to
>read this.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.