Forum Discussion

flynnwt's avatar
flynnwt
Visitor
12 years ago

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?

3 Replies

  • 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
  • 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.
  • 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