I have a carousel of large images. In order to optimize the amount of available memory I am trying to remove the offscreen sprites from the compositor and then invalidate them. However after i have done so using the r2d2_bitmaps command on port 8080 still shows the bitmaps in the graphics memory. What are the steps for removing a sprite and it's corresponding bitmap from memory?
the relevant functions are below
'avalanche is called from a videoplayer, ads is json from the default getads interface
function avalanche(ads) as boolean
av = setup(ads)
if av.load("http://vmg-us.s3.amazonaws.com/demo/designlab/av-demo-app/source/rokucontent.json")
if av.events()
return true
end if
end if
End function
function setup(ads) as object
this = {
port: CreateObject("roMessagePort")
index: {x: 0, y: [0]}
paused: false
fonts: CreateObject("roFontRegistry") 'global font registry
canvas: CreateObject("roImageCanvas") 'user interface
compositor: CreateObject("roCompositor") 'user interface
clock: CreateObject("roTimespan")
adclock: CreateObject("roTimespan")
player: []
tobedrawn: []
ads: ads
bitmaps : []
introplayed: false
interacted : false
load: load
downloading: {}
videocontrolcanvas: []
videocontroldata: []
initialblack: initialblack
spriteinator: spriteinator
canvinator: canvinator
videocontrols: videocontrols
track: track
events: events
sprites: []
canvasitems: []
imagecachecontrol: imagecachecontrol
canTranslate: canTranslate
translate: translate
bounds: bounds
frames: []
adtimer: adtimer
crumblabel: crumblabel
crumblabeldata: []
adtimerdata: []
close: close
get: get
fade: fade
selector: selector
selected: 0
action: action
play: play
openstore: openstore
writeessay: writeessay
waitforfont: []
drawing: 0
cachefull: false
}
this.canvas.SetMessagePort(this.port)
this.canvas.SetLayer(0, { Color: "#000000" })
loading = []
loading.Push({
Text: "Creating Your Interactive Ad Experience..."
TextAttrs: { font:this.fonts.Get("Syfy Medium", 12, False, False), color: "#ffffff" }
TargetRect: {x: 530, y: 250, w: 300, h:200}
})
this.canvas.SetLayer(1, loading)
this.displaymode = "canvas"
this.canvas.Show()
return this
end function
function spriteinator(file as string, sprite) as object
tempfile = "tmp:/"+ file.tokenize("/")[int(file.tokenize("/").count() - 1)].tostr()
if sprite.meta.delta <> invalid
delta = sprite.meta.delta
x = (sprite.meta.offset.tokenize("|")[0].toint() - (sprite.meta.dimension.tokenize("|")[0].toint() * m.index.x * delta.tokenize("|")[0].tofloat()))
else
x = sprite.meta.offset.tokenize("|")[0].toint()
end if
bitmap = CreateObject("roBitmap", tempfile)
m.bitmaps.push(bitmap)
sprite = m.compositor.newsprite(x, sprite.meta.offset.tokenize("|")[1].toint(), createobject("roregion", bitmap, 0, 0, sprite.meta.dimension.tokenize("|")[0].toint(), sprite.meta.dimension.tokenize("|")[1].toint()), sprite.meta.offset.tokenize("|")[2].toint())
if sprite = invalid
m.cachefull = true
end if
return sprite
end function
function imagecachecontrol()
if m.cacherefresh = m.index or m.cacherefresh = invalid
this = {carousel:0,x:0,y:0,grid:[],filecheck:CreateObject("roFileSystem")}
while m.cachefull <> true
for each sprite in m.sprites
if sprite.meta.imgsrc <> invalid
this.tempfile = "tmp:/"+ sprite.meta.imgsrc.tokenize("/")[int(sprite.meta.imgsrc.tokenize("/").count() - 1)].tostr()
end if
this.carouselwidth = m.canvas.getcanvasrect().w
this.carouselheight = m.canvas.getcanvasrect().h
this.gridx = sprite.meta.offset.tokenize("|")[0].toint() / this.carouselwidth
if sprite.meta.delta <> invalid
if sprite.meta.delta.tokenize("|")[0].toFloat() <> 0
this.gridx = this.gridx / sprite.meta.delta.tokenize("|")[0].toFloat()
end if
end if
this.gridy = sprite.meta.offset.tokenize("|")[1].toint() / this.carouselheight
if sprite.meta.delta <> invalid
if sprite.meta.delta.tokenize("|")[1].toFloat() <> 0
this.gridy = int(this.gridy / sprite.meta.delta.tokenize("|")[1].toFloat())
end if
end if
if sprite.meta.position <> invalid
this.gridx = sprite.meta.position.toint()
end if
square = [this.gridx, this.gridy]
if sprite.meta.contentmodel <> "videocontrol"
if (square[0] = m.drawing) or (sprite.meta.contentmodel = "crumb" or sprite.meta.contentmodel = "crumb-behind")
?"drawing sprites for panel" + m.drawing.tostr()
if sprite.meta.scrollabletext<>invalid
if m.fonts.getfont(sprite.meta.scrollabletext.tokenize("|")[5], sprite.meta.scrollabletext.tokenize("|")[6].toint(), False, False) <> invalid
sprite.sprite = m.writeEssay(sprite)
else
m.waitforfont.push(sprite.meta)
end if
end if
if (this.filecheck.exists(this.tempfile) = false) and (sprite.meta.imgsrc <> invalid)
m.get(sprite.meta.imgsrc, sprite.meta)
?"Downloading"
?sprite.meta
else if (sprite.sprite = invalid) and (this.filecheck.exists(this.tempfile) = true) and (sprite.meta.imgsrc <> invalid)
if m.frames.count() = 0
sprite.sprite = m.spriteinator(this.tempfile, sprite)
else
m.tobedrawn.push([this.tempfile, sprite])
end if
end if
end if
end if
end for
if m.events() and m.cachefull <> true
m.drawing = m.drawing + 1
end if
end while
for each sprite in m.sprites
'i decided to remove all the sprites from my parent function to see if anything happened
if sprite.sprite <> invalid
?"REMOVING"
?sprite.meta
stop
sprite.sprite.remove()
sprite.sprite = invalid
global.rungarbagecollector()
end if
end for
end if
end function