One particular problem I was facing - imagine large (near full screen) signs which appear from time to time (eg, "new level" for example). In terms of memory use it is critical to load these only when needed, and get rid of them afterwards.
Here is an exact formula to achieve this using the "single shot" CreateFromTexture method. This explains exactly how to fully "get rid of" such an image.
Starting with the name of your PNG, say imageFileName = "sign18" if the image is sign18.png. The normal Unity command Resources.Load is used to get the PNG from disk and begin using it.
Note that CreateFromTexture creates a gameObject containing the sprite. (handyTempGameObject). Note that the code below then gets the underlying tk2dSprite (handyTempTKS) using GetComponent.
Note carefully that CreateFromTexture also creates in your scene (at root level) the actual sprite COLLECTION needed for the "one-off" sprite. You will see it in the scene at root level and you can get to it via handyTempTKS.collection.gameObject. You must remember to later also Destroy that COLLECTION as well as the sprite game object.
In the example code, I simply move the COLLECTION under the game object (ie, using .parent). This means that later, the COLLECTION will all be trashed when you simply call Destroy on the sprite game object, i.e. you won't forget to separately Destroy it.
The first time you run the code in editor, you will get a warning "you must move _ _ _ shader to a resources folder." Bring up that shader, show in finder. Make a Resources/ folder there beside it (it may exist already). COPY the shader in to that Resources folder.
var handyTempGameObject:GameObject;
var handyTempTKS:tk2dSprite;
var tempTexture:Texture2D;
tempTexture = Resources.Load( imageFileName, Texture2D );
// now create the temporary sprite
// the code shows how to set the size, anchor, screen-size and scale
// note that you can use SpriteCollectionSize.ForTk2dCamera()
// rather than SpriteCollectionSize.Explicit() if relevant to you.
// PS remember to pop the shader in to a Resources/ folder
// you will get a clear alert telling you which shader to move, if you forget.
var tSize:Rect = new Rect(0, 0, tempTexture.width, tempTexture.height);
var tAnch:Vector2 = new Vector2(tempTexture.width/2, tempTexture.height/2);
handyTempGameObject =
tk2dSprite.CreateFromTexture( tempTexture,
tk2dRuntime.SpriteCollectionSize.Explicit( 1, 1536 ),
tSize, tAnch );
handyTempTKS = handyTempGameObject.GetComponent(tk2dSprite);
handyTempTKS.scale = Vector3(2,2,1);
// critical: keep track of the dynamic COLLECTION, to release it later:
handyTempTKS.collection.transform.parent = handyTempGameObject.transform;
// have an empty object called something like "holder" in the correct
// position you want to use the large dynamic sign.
// typically you would have eg. unity animations (perhaps a bounce, etc)
// and anything else (scripts etc) you need on that holder.
// put the dynamic sign in that holder
handyTempGameObject.transform.parent = signHolder;
handyTempGameObject.transform.localPosition = Vector3(0,0,0);
// now use your sprite here, as needs be.
// do whatever you want with the holder, eg,
// slide it across the screen, blink it, whatever.
// use your sprite here, as needs be
// use your sprite here, as needs be
// finally to fully unload everything from memory is this simple
// these two lines of code:
DestroyImmediate( handyTempGameObject );
Resources.UnloadAsset( tempTexture );
// since we put the dynamic collection "under" the sprite game object,
// it is released properly. alternately, leave it at the root level but
// it is essential to remember to call DestroyImmediate on it also
Thanks as always to TK "ultimate gold-plated user support" !