Sequence of GC and unloading assets in Unity3D
Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between
System.GC.Collect();
Resources.UnloadUnusedAssets();
and
Resources.UnloadUnusedAssets();
System.GC.Collect();
AFAIK, both of them are async operations and there might be no difference.
So my question is...
- Are there any difference?
- If so, which is better?
c# memory-management garbage-collection unity3d
add a comment |
Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between
System.GC.Collect();
Resources.UnloadUnusedAssets();
and
Resources.UnloadUnusedAssets();
System.GC.Collect();
AFAIK, both of them are async operations and there might be no difference.
So my question is...
- Are there any difference?
- If so, which is better?
c# memory-management garbage-collection unity3d
UnloadUnusedAsset is async, but actually you can yield to wait until it ends.
– Heisenbug
Jul 9 '13 at 9:00
add a comment |
Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between
System.GC.Collect();
Resources.UnloadUnusedAssets();
and
Resources.UnloadUnusedAssets();
System.GC.Collect();
AFAIK, both of them are async operations and there might be no difference.
So my question is...
- Are there any difference?
- If so, which is better?
c# memory-management garbage-collection unity3d
Sometimes we need to release useless resources manually in game development.
But I'm not sure which is better between
System.GC.Collect();
Resources.UnloadUnusedAssets();
and
Resources.UnloadUnusedAssets();
System.GC.Collect();
AFAIK, both of them are async operations and there might be no difference.
So my question is...
- Are there any difference?
- If so, which is better?
c# memory-management garbage-collection unity3d
c# memory-management garbage-collection unity3d
asked Jul 9 '13 at 1:30
Joon HongJoon Hong
1,0351022
1,0351022
UnloadUnusedAsset is async, but actually you can yield to wait until it ends.
– Heisenbug
Jul 9 '13 at 9:00
add a comment |
UnloadUnusedAsset is async, but actually you can yield to wait until it ends.
– Heisenbug
Jul 9 '13 at 9:00
UnloadUnusedAsset is async, but actually you can yield to wait until it ends.
– Heisenbug
Jul 9 '13 at 9:00
UnloadUnusedAsset is async, but actually you can yield to wait until it ends.
– Heisenbug
Jul 9 '13 at 9:00
add a comment |
2 Answers
2
active
oldest
votes
There is no difference between these two kinds.
System.GC.Collect()
will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets
deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)
In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.
If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.
add a comment |
As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17538570%2fsequence-of-gc-and-unloading-assets-in-unity3d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is no difference between these two kinds.
System.GC.Collect()
will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets
deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)
In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.
If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.
add a comment |
There is no difference between these two kinds.
System.GC.Collect()
will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets
deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)
In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.
If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.
add a comment |
There is no difference between these two kinds.
System.GC.Collect()
will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets
deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)
In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.
If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.
There is no difference between these two kinds.
System.GC.Collect()
will tell .Net collector to collect objects which are managed by mono in the managed heap, while Resources.UnloadUnusedAssets
deals with assets (textures, sounds and other media) which are put in the native heap. The two method do totally different things, so there is no different which one will be executed first. (As you said, they are both async and you just set a flag to suggest the system it could be a good time to do a collect.)
In fact, it is not so common to call GC collect yourself, except you have a good reason. The GC of system will work in proper time, most of calling for forcing a garbage collect are not so necessary as you think.
If you are wondering more about Unity's memory, you can refer to this blog, which can tell you things in detail.
edited Feb 4 '14 at 6:56
answered Jul 9 '13 at 4:32
onevcatonevcat
3,8431625
3,8431625
add a comment |
add a comment |
As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect
add a comment |
As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect
add a comment |
As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect
As unity guy said UnloadUnusedAssets inside also calls System.GC.Collect(); so if you call UnloadUnusedAssets, you don't need to call System.GC.Collect
answered Nov 23 '18 at 5:10
GeorgiyRGeorgiyR
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17538570%2fsequence-of-gc-and-unloading-assets-in-unity3d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
UnloadUnusedAsset is async, but actually you can yield to wait until it ends.
– Heisenbug
Jul 9 '13 at 9:00