6 Replies Latest reply on Jul 10, 2006 4:32 PM by donaldhines

    memory trouble

    donaldhines
      I writing a program that imports pictures. I create a new cast member for each then display then on stage dynamically. I use buddyapi to select the files to import useing 'baGetFilename' I put the file names into a list then create new cast members using 'tMember = new(tType, castLib gImportCastLib)', then create a puppetsprite and the assign the sprite my new cast member "sprite(pSpriteNumber).member = tMember.name'. This works fine until I import 30 + files. I get out of memory error or it just locks up. I use the same variable 'tMember' for each new picture. Is dump the memory associated with 'tMember'' after the cast member is created???

        • 1. Re: memory trouble
          Level 7
          Since you're importing on the fly the images will stay in memory. They are
          imported into director as bitmaps, not jpegs or some other form you might
          have on disc. This will make them, in most cases, significantly larger than
          what you might have expected. Between the two things I mentioned, you will
          run into memory problems. Why not just import the one you are displaying
          and change the fileName of that member as you need to change the displayed
          image?

          Once the cast member is created, it is in the cast. Just because you assign
          a new cast member to the same variable, that cast member is still in memory,
          it's just not associated with tMember anymore. If you specify the position
          in the cast then it will in fact overwrite the last imported image because
          its using the same cast member. Your way creates all separate cast members.



          --
          Craig Wollman
          Word of Mouth Productions

          phone 212 928 9581
          fax 212 928 9582
          159-00 Riverside Drive West #5H-70
          NY, NY 10032
          www.wordofmouthpros.com


          "donaldhines" <webforumsuser@macromedia.com> wrote in message
          news:e8mqur$7r5$1@forums.macromedia.com...
          >I writing a program that imports pictures. I create a new cast member for
          >each
          > then display then on stage dynamically. I use buddyapi to select the files
          > to
          > import useing 'baGetFilename' I put the file names into a list then
          > create new
          > cast members using 'tMember = new(tType, castLib gImportCastLib)', then
          > create
          > a puppetsprite and the assign the sprite my new cast member
          > "sprite(pSpriteNumber).member = tMember.name'. This works fine until I
          > import
          > 30 + files. I get out of memory error or it just locks up. I use the same
          > variable 'tMember' for each new picture. Is dump the memory associated
          > with
          > 'tMember'' after the cast member is created???
          >
          >
          >
          > global gFullfilelist
          > global gDefaultMediaItem
          > global gMediaList
          > global gImportCastLib
          > global gNextSpriteNumber
          >
          > --Seperate Short FileName
          > on ParseName(fileRec)
          > flength= length(fileRec)
          > lastFolderPos=0
          > repeat with a=1 to flength
          > if chars(fileRec, a, a) ="\"then
          > lastFolderPos=a
          > end if
          > end repeat
          >
          > shortname=chars(fileRec, lastFolderPos+1, flength)
          > return shortname
          > end
          > --Seperate Path
          > on ParsePath(fileRec)
          > flength= length(fileRec)
          > lastFolderPos=0
          > repeat with a=1 to flength
          > if chars(fileRec, a, a) ="\"then
          > lastFolderPos=a
          > end if
          > end repeat
          >
          > pathname=chars(fileRec, 1, lastFolderPos)
          > return pathname
          > end
          > --Seperate Type
          > on ParseType(fileRec)
          > flength= length(fileRec)
          > typePos=0
          > repeat with a=1 to flength
          > if chars(fileRec, a, a) ="."then
          > typePos=a
          > end if
          > end repeat
          >
          > typename=chars(fileRec, typePos+1, flength)
          > return typename
          > end
          >
          > on mouseUp me -- obtain file name to save file to:
          > set filelist=[]
          > set filelist = baGetFilename( "open", "c:\temp", "", "JPEG|*.jpg",
          > 512+256+524288 , "Select Photos", false, 100, 100 )
          >
          > listamount=gFullfilelist.count
          > fileamount=filelist.count
          > UPDATESTAGE
          > repeat with f=1 to fileamount
          >
          > gFullfilelist[listamount+f]=filelist[f]
          >
          > end repeat
          > gMediaList=[]
          > gDefaultMediaItem= [ #fname : "blank" , #ftype : "blank" , #fullpath :
          > "blank" , #importedYet : "no", #mem : "none" ]
          >
          > repeat with f=1 to fileamount
          > gMediaList[f]=duplicate(gDefaultMediaItem)
          > end repeat
          >
          > repeat with f=1 to fileamount
          > gMediaList[f].fname=ParseName(gFullfilelist[f])
          > gMediaList[f].fullpath=ParsePath(gFullfilelist[f])
          > gMediaList[f].ftype=#bitmap
          > -- put gMediaList[f].fname
          > -- put gMediaList[f].ftype
          > end repeat
          > repeat with f=1 to fileamount
          >
          > -- pulling the TYPE of cast member to create, from our media
          > description
          > list:
          > tType = gMediaList[f].ftype
          > --creating a new member in our "imported files" castling, and saving
          > the
          > resulting member location
          > tMember = new(tType, castLib gImportCastLib)
          > -- setting the filename of the new member:
          > tMember.filename = gMediaList[f].fullpath &gMediaList[f].fname
          > -- this will make most bitmaps look better under less than 32 bits of
          > color:
          > if tType = #bitmap then tMember.dither = 1 ------I get the Error
          > here
          > after 38 pictures imported--------------
          > gMediaList[f].mem = tMember
          >
          > gMediaList[f].importedYet = "yes"
          >
          > gNextSpriteNumber = gNextSpriteNumber + 1
          > ----------Record the sprite number used for this object
          > pSpriteNumber = gNextSpriteNumber
          > ----------Claim control of this sprite
          > puppetSprite(pSpriteNumber, TRUE)
          > ----------Assign a cast member to this sprite
          > sprite(pSpriteNumber).member = tMember.name
          > ----------Randomly position this sprite on the stage
          > sprite(pSpriteNumber).width=120
          > sprite(pSpriteNumber).height=90
          > x = (((gNextSpriteNumber-20) mod 5)*125)+150
          > y = (integer((gNextSpriteNumber-20)/5)*95)+150
          > put "vert = "&y
          > put "horz = "&x
          > put gNextSpriteNumber
          > put "*******************"
          > sprite(pSpriteNumber).locH = x
          > sprite(pSpriteNumber).locV = y
          > ----------Return a reference to the new object
          > end repeat
          > if (gNextSpriteNumber-20) mod 5>5 then
          > repeat with x= 3 to 6
          > sprite(x).visible = true
          > end repeat
          > end if
          > end Text Text
          >


          • 2. Re: memory trouble
            Level 7
            The saveMovie command has given me mixed results but may be one way to
            free ram as the newl imported images are saved to disk.


            It's easy to calculate the ram overhead for an imported bitmap

            Width * Height * 4 ( * 4 for 32 bit deptyh images)



            Changing your stagety so only the currently needed image is imported,
            rather than importing a bunch up fronty, can keep ram overhead down,
            changing the fileName of a linked external bitmap member is one way to
            change the image on the gly.
            • 3. Re: memory trouble
              Level 7
              > changing the fileName of a linked external bitmap member is one way to
              > change the image on the gly.

              I can recommend that method, if you can use external images in your
              application.
              Using between 1000-3000 external images (640x480), showing 8 images/second
              with no issues concerning memory.


              • 4. Re: memory trouble
                Level 7
                From seeing your code, I guess that that you import fullsize images, but
                display them smaller - and you need to show all images at the same time. As
                Craig mention, you'll run into memoryproblems.
                You could:
                - Link to one external image a time, create a thumbnail in the needed size
                with copyPixels, and use puppetSprite to show that.
                - Check out Valentins Image Xtra, that can extract embedded thumbnails from
                headers (that feature is Jpeg only)
                http://staff.dasdeck.de/valentin/xtras/image/


                • 5. Re: memory trouble
                  donaldhines Level 1
                  I checked out Valentins Image Xtra, looks like it may do the trick, but the documentation on it isn't so great and the test program did'nt work.. But I think using copyPixels to create a thumb will do the trick. See my problem is a may have to display numerous high-Def pictures at once.

                  I appriciate everyones imput, you've been very helpful.

                  Thank You
                  • 6. Re: memory trouble
                    donaldhines Level 1
                    Here's a slight rewrite on that code. WORKS Great--------Thanks for all the Help !