Actionscript 3을 사용하여 ByteArray 언로드
ByteArray
ActionScript 3을 사용하여 메모리에서 강제로를 언로드하려면 어떻게합니까 ?
나는 다음을 시도했다 :
// First non-working solution
byteArray.length = 0;
byteArray = new ByteArray();
// Second non-working solution
for ( var i:int=0; i < byteArray.length; i++ ) {
byteArray[i] = null;
}
나는 당신이 걱정할 것이 없다고 생각합니다. 경우 System.totalMemory
다운되면 당신은 휴식을 취할 수 있습니다. 새로 해제 된 메모리를 회수하지 않는 것은 OS 일 수 있습니다 (다음 번에 Flash Player가 더 많은 메모리를 요구할 것으로 예상 됨).
메모리를 많이 사용하는 다른 작업을 시도하면 Flash Player에 할당 된 메모리가 줄어들고 대신 다른 프로세스에 사용된다는 것을 알 수 있습니다.
내가 이해했듯이 최신 OS의 메모리 관리는 각 프로세스에 할당 된 양 또는 할당 된 총 양을 보는 관점에서 직관적이지 않습니다.
Mac을 5 분 동안 사용하면 3GB RAM의 95 %가 사용되며 그대로 유지되지만 절대 다운되지 않습니다. 이것이 OS가 메모리를 처리하는 방식입니다.
다른 곳에서 필요하지 않은 한 종료 된 프로세스에도 메모리가 할당되어 있습니다 (예를 들어 다음 번에 더 빨리 시작할 수 있음).
(긍정적이지는 않지만 ...)
AS3는 비 결정적 가비지 컬렉션을 사용합니다. 즉, 런타임이 그렇게 느껴질 때마다 참조되지 않은 메모리가 해제됩니다 (일반적으로 실행하는 데 비용이 많이 드는 작업이므로 실행할 이유가없는 경우). 이것은 대부분의 최신 가비지 수집 언어 (예 : C # 및 Java)에서 사용하는 것과 동일한 접근 방식입니다.
가리키는 메모리 byteArray
또는 배열 자체 내의 항목에 대한 다른 참조가 없다고 가정하면 byteArray
선언 된 범위를 종료 한 후 어느 시점에서 메모리가 해제됩니다 .
가비지 컬렉션을 강제 할 수 있지만 실제로는 안됩니다. 그렇게한다면 테스트 용으로 만 수행하십시오. 프로덕션에서 수행하면 도움이되는 것보다 훨씬 성능이 저하됩니다.
GC를 강제하려면 다음을 시도하십시오 (예, 두 번).
flash.system.System.gc();
flash.system.System.gc();
이 기사를보십시오
http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html
IANA 액션 스크립트 프로그래머,하지만 내가 느끼는 느낌은 가비지 수집기가 원할 때 실행되지 않을 수 있기 때문입니다.
따라서 http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/
그래서 나는 그들의 소장 코드를 시험 해보고 그것이 도움이되는지 확인하는 것이 좋습니다
private var gcCount:int;
private function startGCCycle():void{
gcCount = 0;
addEventListener(Event.ENTER_FRAME, doGC);
}
private function doGC(evt:Event):void{
flash.system.System.gc();
if(++gcCount > 1){
removeEventListener(Event.ENTER_FRAME, doGC);
setTimeout(lastGC, 40);
}
}
private function lastGC():void{
flash.system.System.gc();
}
나는 당신이 당신 자신의 질문에 대답했다고 믿습니다 ...
System.totalMemory
할당되지 않은 "사용"중인 총 메모리 양을 제공합니다. 애플리케이션이 20MB 만 사용하는 것이 정확하지만 향후 할당을 위해 무료로 제공되는 5MB가 있습니다.
어도비 문서가 메모리를 관리하는 방식을 밝힐 지 모르겠습니다 ...
안타깝게도 플래시 / 액션 스크립트의 메모리 관리에 관해서 는 할 수있는 일이 많지 않습니다. ActionScript는 사용하기 쉽게 설계되었으므로 사람들이 메모리 관리에 대해 걱정할 필요가 없었습니다.
다음은 해결 방법 ByteArray
입니다. 변수 를 만드는 대신 이것을 시도하십시오.
var byteObject:Object = new Object();
byteObject.byteArray = new ByteArray();
...
//Then when you are finished delete the variable from byteObject
delete byteObject.byteArray;
Where byteArray
is a dynamic property of byteObject
, you can free the memory that was allocated for it.
So, if I load say 20MB from MySQL, in the Task Manager the RAM for the application goes up by about 25MB. Then when I close the connection and try to dispose the ByteArray, the RAM never frees up. However, if I use System.totalMemory, flash player shows that the memory is being released, which is not the case.
Is the flash player doing something like Java and reserving heap space and not releasing it until the app quits?
Well yes and no, as you might have read from countless blogposts the GC in AVM2 is optimistic and will work it's own mysterious ways. So it does work a bit like Java and tries to reserve heap space, however if you let it long enough and start doing other operations that are consuming some significant memory it will free that previous space. You can see this using the profiler over night with some tests running on top of your app.
So, if I load say 20MB from MySQL, in the Task Manager the RAM for the application goes up by about 25MB. Then when I close the connection and try to dispose the ByteArray, the RAM never frees up. However, if I use System.totalMemory, flash player shows that the memory is being released, which is not the case.
The player is "releasing" the memory. If you minimize the window and restore it you should see that the memeory is now much closer to what System.totalMemory shows.
You might also be interested in using FlexBuilder's profiling tools which can show you if you really have memory leaks.
Use these resources:
and this
참고URL : https://stackoverflow.com/questions/34/unloading-a-bytearray-using-actionscript-3
'program story' 카테고리의 다른 글
Iframe 콘텐츠가로드 된시기 감지 (크로스 브라우저) (0) | 2020.09.22 |
---|---|
공식 JavaScript 참조가없는 이유는 무엇입니까? (0) | 2020.09.22 |
C ++에 기본 클래스가없는 이유는 무엇입니까? (0) | 2020.09.21 |
Node.js 라이브러리 Winston을 사용하여 로그에 타임 스탬프를 추가하려면 어떻게해야합니까? (0) | 2020.09.21 |
이해하기 쉬운 설명으로 Java에서 실행 가능이란 무엇입니까? (0) | 2020.09.21 |