Stack size increases dramatically when I DELETE pictures

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
larryh
Posts: 32
Joined: Sat Mar 22, 2008 6:02 pm

Stack size increases dramatically when I DELETE pictures

Post by larryh » Mon Nov 24, 2008 9:09 am

Hi,

I noticed that I had accidentally created a card with all the graphics that I use for buttons, etc. and that I duplicated and filled in this card for every record I have (1000s of records).

I thought that if I created a substack with one card with the images and then have the buttons point to the new IDs in the Image Library that it would save space. That way, each image for each button is not being duplicated for each record I have (maybe it isn't anyhow ... these images were part of a background).

When I removed the images, the stack size increased in size from 9 MB to almost 25 MB!!! I'm trying to understand why.

Larry

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Nov 24, 2008 11:56 am

Hi Larry,

Are you sure that you are comparing stack sizes at the right moments? Have you saved the stack right before and immediately after deleting the pictures?

You could have a look in the application browser to see which objects are there. Perhaps there are some unexpected objects laying around?

A stack with literally thousands of cards and on each card a few buttons and fields as well as text in the fields can easily take several megabytes. I am not very surprised by the size of your stack.

Actually, I think you are following the wrong approach. By keeping all records on cards, your stack will become relatively big and extremely slow. Soon, the find command will take several minutes to complete. I did this with a stack with 36000 records and on a 350Mhz machine, I needed about 20 minutes to find a record (several years ago).

You will get a much smaller and faster stack if you keep all your data in a file or in custom properties. Search for the data you need with offset functions or repeat loops, for example. Another very fast method is the use of a real database, such as SQLite or mySQL.

Good luck,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

larryh
Posts: 32
Joined: Sat Mar 22, 2008 6:02 pm

Post by larryh » Mon Nov 24, 2008 6:04 pm

Hi Mark,

Yes, my goal this week is to convert it over to SQLite.

Thankfully I kept backups of my project. I have the project at <10MB and then after I run the following script. Once that is saved it rests at close to 23MB.

on mouseUp
--Clean up other cards in main stack to get rid of copied pictures that we really don't need lying around.
lock screen
put fld fDeleteThese into vDeletionList
put the number of cards in stack "TSI.rev" into vTotalCards
repeat with tCardRun = 1 to vTotalCards
go to card tCardRun of stack "TSI.rev"
put number of lines of vDeletionList into vDeletionListNumLines
repeat with tImageRun = 1 to vDeletionListNumLines
put line tImageRun of vDeletionList into vImageName
if exists (image vImageName of card tCardRun of stack "TSI.rev") then
delete image vImageName of card tCardRun of stack "TSI.rev"
end if
end repeat
end repeat
unlock screen
end mouseUp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Nov 24, 2008 7:46 pm

Hi Larry,

I'm playing with your script, but need to know what fDeleteThese is. Is that a variable or a field name? Why do you refer to your stack as "TSI.rev" and not simply "TSI"?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

larryh
Posts: 32
Joined: Sat Mar 22, 2008 6:02 pm

Post by larryh » Tue Nov 25, 2008 1:00 am

Hi Mark,

fDeleteThese is a field with a picture name on each line:

eg.

forwardarrow.png
reversearrow.png
search.png
add.png
correct.png
wrong.png
etc.

I normally don't include the extension in the stack name but this time I did.

Larry

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Nov 25, 2008 1:23 am

Hi Larry,

The different isn't really that big, but you might try the following script. Before you do anything else, after running the script, check the size of the stack. Is it still larger than you expect?

Code: Select all

on mouseUp
   --Clean up other cards in main stack to get rid of copied pictures that we 
   -- really don't need lying around.
   lock screen
   lock messages
   put fld "fDeleteThese" into vDeletionList
   go stack "TSI.rev" in new window
   repeat with tCardRun = 1 to number of cards of this stack
      repeat for each line myImg in vDeletionList
         if there is an img myImg of cd tCardRun then delete img myImg of cd tCardRun
      end repeat
   end repeat
   unlock screen
   unlock messages
   -- compress and save, same as Save in File menu
   compress this stack
   save this stack
end mouseUp
Do you already have the pictures copied to a substack, before you delete the pictures?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

larryh
Posts: 32
Joined: Sat Mar 22, 2008 6:02 pm

Post by larryh » Tue Nov 25, 2008 2:02 am

I don't get it ... your script works (apart from the compress this stack line). And the resulting file is somewhat smaller. Hmmmm. So you need to go to the stack and then iterate through ... that makes sense to me.

Well Mark ... once again you have led me into the deeper mysteries of RunRev.

Thanks!

Larry

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Nov 25, 2008 2:19 am

Hi Larry,

Do you already have the pictures copied to a substack, before you delete the pictures?

How much smaller is the stack exactly, after running the script?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

larryh
Posts: 32
Joined: Sat Mar 22, 2008 6:02 pm

Post by larryh » Tue Nov 25, 2008 6:13 am

Hi Mark,

I was incorrect about the size difference. What I was seeing was the tempory difference as revolution writes out the file.

I do have a substack with all of the artwork in it. Before hand it's 9683K. After running the script it is hardly any different ... 9628.

Larry

Post Reply