Created
April 1, 2013 12:45
-
-
Save sonygod/5284759 to your computer and use it in GitHub Desktop.
gc memories clean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package ; | |
| import flash.display.Bitmap; | |
| import flash.display.BitmapData; | |
| import flash.display.Loader; | |
| import flash.display.LoaderInfo; | |
| import flash.display.MovieClip; | |
| import flash.display.StageAlign; | |
| import flash.display.StageScaleMode; | |
| import flash.Lib; | |
| import flash.events.Event; | |
| import flash.net.URLRequest; | |
| import flash.system.LoaderContext; | |
| import flash.errors.Error; | |
| import flash.net.LocalConnection; | |
| import flash.system.System; | |
| using Bm; | |
| /** | |
| * ... | |
| * @author sonygod | |
| */ | |
| class Main { | |
| public static var max:Int = 200; | |
| public static var no:Int = 0; | |
| static function main() { | |
| var stage = Lib.current.stage; | |
| stage.scaleMode = StageScaleMode.NO_SCALE; | |
| stage.align = StageAlign.TOP_LEFT; | |
| // entry point | |
| for (i in 0...max) { | |
| var loader:Loader = new Loader(); | |
| loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad); | |
| loader.load(new URLRequest("test.jpg")); | |
| loader = null; | |
| } | |
| } | |
| public static function onLoad(event:Event):Void { | |
| no++; | |
| var loader:LoaderInfo = event.currentTarget; | |
| GlobalTimer.setTimeout(test, 1000 + (no * 5), [loader]); | |
| } | |
| public static function test(loader:LoaderInfo):Void { | |
| var bitmap:Bitmap = Lib.as(loader.content, Bitmap); | |
| bitmap.bitmapData.dispose(); | |
| bitmap.bitmapData = null; | |
| bitmap = null; | |
| bitmap = null; | |
| loader.loader.unloadAndStop(); | |
| loader = null; | |
| no--; | |
| //trace(no); | |
| if (no <= 10) { | |
| //much >1 gc | |
| gc(); | |
| } | |
| } | |
| public static function gc() { | |
| trace("清理之前" + System.totalMemory); | |
| try { | |
| new LocalConnection().connect('foo'); | |
| new LocalConnection().connect('foo'); | |
| } catch (e:Error) { | |
| } | |
| trace("清理之后" + System.totalMemory); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment