Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
flynnwt
Visitor

Garbage Collector Bug/WAD?

I think I am seeing a problem related to garbage collection. I am calling a function from my main event loop which initiates some async requests using this function:

function getImageAsync(port, file, url) 
u = CreateObject("roUrlTransfer")
u.SetMessagePort(port)
u.setUrl(url)
if not u.asyncGetToFile(file) then
print "getImageAsync() failed!"
end if
return u.GetIdentity()
end function


I am always receiving event code=-10001 (Cancelled). I am able to get it to work by creating the roUrlTransfer objects in the calling function (and saving them in another object). This function now works...

function getImageAsync2(u, port, file, url) 
u.SetMessagePort(port)
u.setUrl(url)
if not u.asyncGetToFile(file) then
print "getImageAsync() failed!"
end if
return u.GetIdentity()
end function


I've just started playing with BrightScript, but it appears the roUrlTransfer object is being freed when the function returns even though the request is active. Would this be expected behavior?
0 Kudos
3 REPLIES 3
NewManLiving
Visitor

Re: Garbage Collector Bug/WAD?

Your transfer object must survive the trip
Around the world. If it goes out of scope
Then it is returned as cancelled. Return u
And hold it until the completion
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
flynnwt
Visitor

Re: Garbage Collector Bug/WAD?

Yes, I now keep the object instead of just the identity to match to the event. I would have expected the roUrlTransfer component to add a reference when it is created so that it stays active until the event is created.
0 Kudos
NewManLiving
Visitor

Re: Garbage Collector Bug/WAD?

Yes initially you would think the reference is
Is held but when you get cancelled you find out its
Not The same thing applies to the texture
Manager if you get around to using that
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.