Jump to content

  • Log In with Google      Sign In   
  • Create Account


Memory leak when doing multiple thread


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Knight52   Members   -  Reputation: 171

Like
0Likes
Like

Posted 21 September 2012 - 01:04 AM

I know how bad it is to go multi-threading, but I don't know how else I will load stuff behind the loading screen.
No memory leaks when I do single thread, but when I create another thread to handle that same function, I got memory leaks. That function handles some Direct3D loading too. Do I have to release something before exiting the thread?

Sponsor:

#2 Kaptein   Prime Members   -  Reputation: 1514

Like
1Likes
Like

Posted 21 September 2012 - 02:12 AM

check if the directx functions you are using are thread-safe
without any code, it's hard to help you

as you should know, in threading, all threads can access the same (shared) memory
without mutex locks, you can't be certain that the same memory isnt accessed or overwritten by threads at the same time
one bad example is: if you allocate memory at the same time on both threads, both pointers could end up with the same value! (memory offset)
threads don't necessarily start in the order you started them in
they don't execute at the same speed
just google threads! theres LOTS you need to know about them before you can start using them in a game!!
start using threads in a small test project and find out what you can and can't do!

#3 rip-off   Moderators   -  Reputation: 6874

Like
1Likes
Like

Posted 21 September 2012 - 02:25 AM

I know how bad it is to go multi-threading, but I don't know how else I will load stuff behind the loading screen.

Have you tried non-blocking or asynchronous I/O?

#4 Knight52   Members   -  Reputation: 171

Like
0Likes
Like

Posted 21 September 2012 - 05:49 AM

check if the directx functions you are using are thread-safe without any code, it's hard to help you as you should know, in threading, all threads can access the same (shared) memory without mutex locks, you can't be certain that the same memory isnt accessed or overwritten by threads at the same time one bad example is: if you allocate memory at the same time on both threads, both pointers could end up with the same value! (memory offset) threads don't necessarily start in the order you started them in they don't execute at the same speed just google threads! theres LOTS you need to know about them before you can start using them in a game!! start using threads in a small test project and find out what you can and can't do!


I know how bad it is to go multi-threading, but I don't know how else I will load stuff behind the loading screen.

Have you tried non-blocking or asynchronous I/O?


I've created a mutex lock, still doesn't fix the leaks. I've tried WM_TIMER which I understand it's one of asyn io processes, doesn't fix the leak either. So I don't think it's multi-threading resource issue.
Here's the some sort of algorithm. Hope this will help.

Retrieve info
if player is initialized.
{
	 separate the player and equipments from resource pool.
}
Flush the resource pool. This includes Skybox primitives and texture, object's model and animation, terrain, and lights' shadow maps.
Open the file
if(file == null)
{
	 Messagebox ("cannot open file")
	 exit
}
Load new resources by reading info from the file.
if player is initialized
{
	 add the player and equipments back to resource pool
}
else
{
	 initialize player and add it to the resource pool
}
delete file.
hide loading screen.
release mutex
close mutex

Edited by Knight52, 21 September 2012 - 05:50 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS