Hello Guest

Author Topic: memory leak while using tk2dSprite.CreateFromTexture()  (Read 3859 times)

jhocking

  • Newbie
  • *
  • Posts: 5
    • View Profile
memory leak while using tk2dSprite.CreateFromTexture()
« on: February 22, 2014, 12:11:09 am »
I was really pleased to see that I can display images downloaded from the internet by using tk2dSprite.CreateFromTexture()

However I've noticed that when I do so, and then Destroy the sprite once I'm done with it, the scene gets littered with all the sprite collections spawned for the dead sprites. I'm guessing I can avoid this memory leak by using tk2dSpriteCollectionData.CreateFromTexture(), so that I can directly reference and recycle sprite collections, but it does seem a bit roundabout to do things that way.

Is there a way to use tk2dSprite.CreateFromTexture() while clearing out dead sprite collections? This isn't a huge memory leak, since the sprite collections are all cleared out when I load a new level, but it's still something I want to fix.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: memory leak while using tk2dSprite.CreateFromTexture()
« Reply #1 on: February 22, 2014, 12:49:40 pm »
I wouldn't consider that a memory leak.
The sprite collections are there (and visible in the scene) so you can Destroy them when you're done with it. It is your responsibility to destroy them when you're done using the sprites & the collections. Eg. if you're only ever creating one sprite from a collection - just Destroy(sprite.Collection.gameObject) before Destroy(sprite.gameObject). Otherwise you need to manage and destroy the collection when you're done with it.

jhocking

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: memory leak while using tk2dSprite.CreateFromTexture()
« Reply #2 on: February 23, 2014, 02:11:28 am »
Interesting, I didn't realize you can get the sprite collection using sprite.Collection; since the CreateFromTexture() command returns a GameObject, I didn't know how to get the sprite collection that was created. Thanks!

(just to be pedantic, it is a memory leak but apparently one that's on us to take care of, and not a problem with 2D Toolkit. It might be worth reminding people in the script reference that they can use sprite.Collection)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: memory leak while using tk2dSprite.CreateFromTexture()
« Reply #3 on: February 23, 2014, 09:01:35 pm »
I've added a note to the CreateFromTexture docs, will be in the next docs push.