Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

sdl - What's the point of SDL_DestroyWindow() and SDL_Quit()?

I was talking with a friend and he said that they just slow down the closing time of the program and are useless since operating systems will automatically clean everything up and will do it faster.

question from:https://stackoverflow.com/questions/65841149/whats-the-point-of-sdl-destroywindow-and-sdl-quit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since some programs could crash or be killed, OS have to ensure freeing what it could. Sometimes that is not enough - e.g. if you've disabled screensaver, would it be enabled back? If you set fullscreen videomode with different resolution, would resolution reset after your program close? If you use rumble on gamepad, would it stop, and if so, when? There are a lot of questions and no answers, as all that is OS dependent.

And sometimes you actually need to close window without finishing your program.

If you happen to corrupt memory heap or stomped data, explicit free is more likely to crash your program, so you may notice it earlier. Look up famous "Thank you for playing Wing Commander!" story.

You pretty much lose ability to use memory leak detector like valgrind as it would report quite a lot of leaks if you don't do finalisation.

More important question is why would you want to avoid explicit finalisation. To presumably save some minuscule time? By doing finalisation on your side you slightly reduce amount of work other OS parts will do on process finish, so - probably yes, but very unlikely to be noticeable. But it is likely to raise questions if someone else will look at your code (that someone is probably yourself several years later).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...