{"id":69,"date":"2009-07-12T22:49:16","date_gmt":"2009-07-12T18:49:16","guid":{"rendered":"http:\/\/www.jrtwine.com\/blog\/?p=69"},"modified":"2009-07-16T23:04:47","modified_gmt":"2009-07-16T19:04:47","slug":"xna-audio-troubles","status":"publish","type":"post","link":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/","title":{"rendered":"XNA Audio Troubles&#8230;"},"content":{"rendered":"<p>So as I am adding sound effects to the game, I noticed that over time it would consume more and more memory and start to slow down.  Another thing that would happen is that the audio would drag out and get <em>sloooooooooooooooooow<\/em>.<\/p>\n<p>Now, I consider myself a pretty decent developer and I took steps to ensure that objects are reused where possible, instead of being <strong>new<\/strong>-ed up over and over again (.NET may be an environment that takes care of a lot of the dirty work of managing memory, but you still need to remember that it is a limited resource and code accordingly).  <\/p>\n<p>I should have taken the slowed sounds as a hint, but I went down the path of tracking objects and Garbage Collections to make sure that the object caches were healthy and the few objects that are destroyed and recreated are cleaned up in an orderly fashion as well.<\/p>\n<p>After going though all that, I realized that the XACT-related classes are the culprits.  If I turn off the sound, memory usage remains stable, even after running the game (in its attract mode) for more than 12 hours.  It normally started to get slow after 45 minutes or so.<\/p>\n<p>Looking up memory-related issues with audio in XNA, I read that other people have a similar problem, but only if they are not calling <strong>Update(&#8230;)<\/strong> in the Audio Engine during each frame.  However, I <strong><em>AM<\/em><\/strong> calling <strong>Update(&#8230;)<\/strong> and am still having the problem.  I even added additional calls to <strong>Update(&#8230;)<\/strong> from other locations in the code, but to no avail.<\/p>\n<p>I even tried manually managing each Cue instance by storing them in a collection when they are played and then <strong>Dispose()<\/strong>-ing them when they are done playing.  No difference.<\/p>\n<p>I have temporarily resolved the issue by manually cleaning up and reallocating the Audio Engine at certain times during the game &#8212; between the end of a level and the start of a new one, and whenever the Title Screen transitions to the next screen when the game is in attract mode.  Kludgy?  Yep!  But it works, and until an updated version of the XNA Framework is available that possibly fixes this bug, it will have to do.<\/p>\n<p>Oh, and I used The GIMP to create a starburst graphic and am briefly displaying it as a &#8220;superluminal flash&#8221; (the warp equivlent of a sonic boom) when the player&#8217;s ship goes to warp.  It looks sweet, even if I do say so myself! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had a little trouble with a memory leak using the XACT classes to play sounds.  Had to get a little kludgy to fix it.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[4,46],"tags":[52,48,51,50,53,49,47,42],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-developing","category-xnagame-development","tag-audio","tag-game","tag-leak","tag-memory","tag-sound","tag-update","tag-xact","tag-xna"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.5.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"James R. Twine\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.5.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"James R. Twine&#039;s Blog - Random, Sometimes Useful Stuff\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"XNA Audio Troubles\u2026 - James R. Twine&#039;s Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2009-07-12T18:49:16+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2009-07-16T19:04:47+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"XNA Audio Troubles\u2026 - James R. Twine&#039;s Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#blogposting\",\"name\":\"XNA Audio Troubles\\u2026 - James R. Twine's Blog\",\"headline\":\"XNA Audio Troubles&#8230;\",\"author\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/author\\\/jtwine\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#articleImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/77d36362e353ec1c88adc48b48055faee96497898a208d3a6a05897d4902e552?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"James R. Twine\"},\"datePublished\":\"2009-07-12T22:49:16+00:00\",\"dateModified\":\"2009-07-16T23:04:47+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#webpage\"},\"articleSection\":\"Developing, XNA\\\/Game Development, audio, Game, leak, memory, sound, Update, XACT, XNA\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/category\\\/developing\\\/#listItem\",\"name\":\"Developing\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/category\\\/developing\\\/#listItem\",\"position\":2,\"name\":\"Developing\",\"item\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/category\\\/developing\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#listItem\",\"name\":\"XNA Audio Troubles&#8230;\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#listItem\",\"position\":3,\"name\":\"XNA Audio Troubles&#8230;\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/category\\\/developing\\\/#listItem\",\"name\":\"Developing\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/#person\",\"name\":\"Squiz\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/author\\\/jtwine\\\/#author\",\"url\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/author\\\/jtwine\\\/\",\"name\":\"James R. Twine\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/77d36362e353ec1c88adc48b48055faee96497898a208d3a6a05897d4902e552?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"James R. Twine\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#webpage\",\"url\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/\",\"name\":\"XNA Audio Troubles\\u2026 - James R. Twine's Blog\",\"description\":\"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/xna-audio-troubles\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/author\\\/jtwine\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/author\\\/jtwine\\\/#author\"},\"datePublished\":\"2009-07-12T22:49:16+00:00\",\"dateModified\":\"2009-07-16T23:04:47+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/\",\"name\":\"James R. Twine's Blog\",\"description\":\"Random, Sometimes Useful Stuff\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/jrtwine.com\\\/blog\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"XNA Audio Troubles\u2026 - James R. Twine's Blog","description":"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it.","canonical_url":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#blogposting","name":"XNA Audio Troubles\u2026 - James R. Twine's Blog","headline":"XNA Audio Troubles&#8230;","author":{"@id":"https:\/\/jrtwine.com\/blog\/author\/jtwine\/#author"},"publisher":{"@id":"https:\/\/jrtwine.com\/blog\/#person"},"image":{"@type":"ImageObject","@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#articleImage","url":"https:\/\/secure.gravatar.com\/avatar\/77d36362e353ec1c88adc48b48055faee96497898a208d3a6a05897d4902e552?s=96&d=mm&r=g","width":96,"height":96,"caption":"James R. Twine"},"datePublished":"2009-07-12T22:49:16+00:00","dateModified":"2009-07-16T23:04:47+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#webpage"},"isPartOf":{"@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#webpage"},"articleSection":"Developing, XNA\/Game Development, audio, Game, leak, memory, sound, Update, XACT, XNA"},{"@type":"BreadcrumbList","@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/jrtwine.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/jrtwine.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/jrtwine.com\/blog\/category\/developing\/#listItem","name":"Developing"}},{"@type":"ListItem","@id":"https:\/\/jrtwine.com\/blog\/category\/developing\/#listItem","position":2,"name":"Developing","item":"https:\/\/jrtwine.com\/blog\/category\/developing\/","nextItem":{"@type":"ListItem","@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#listItem","name":"XNA Audio Troubles&#8230;"},"previousItem":{"@type":"ListItem","@id":"https:\/\/jrtwine.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#listItem","position":3,"name":"XNA Audio Troubles&#8230;","previousItem":{"@type":"ListItem","@id":"https:\/\/jrtwine.com\/blog\/category\/developing\/#listItem","name":"Developing"}}]},{"@type":"Person","@id":"https:\/\/jrtwine.com\/blog\/#person","name":"Squiz"},{"@type":"Person","@id":"https:\/\/jrtwine.com\/blog\/author\/jtwine\/#author","url":"https:\/\/jrtwine.com\/blog\/author\/jtwine\/","name":"James R. Twine","image":{"@type":"ImageObject","@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/77d36362e353ec1c88adc48b48055faee96497898a208d3a6a05897d4902e552?s=96&d=mm&r=g","width":96,"height":96,"caption":"James R. Twine"}},{"@type":"WebPage","@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#webpage","url":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/","name":"XNA Audio Troubles\u2026 - James R. Twine's Blog","description":"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/jrtwine.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/#breadcrumblist"},"author":{"@id":"https:\/\/jrtwine.com\/blog\/author\/jtwine\/#author"},"creator":{"@id":"https:\/\/jrtwine.com\/blog\/author\/jtwine\/#author"},"datePublished":"2009-07-12T22:49:16+00:00","dateModified":"2009-07-16T23:04:47+00:00"},{"@type":"WebSite","@id":"https:\/\/jrtwine.com\/blog\/#website","url":"https:\/\/jrtwine.com\/blog\/","name":"James R. Twine's Blog","description":"Random, Sometimes Useful Stuff","inLanguage":"en-US","publisher":{"@id":"https:\/\/jrtwine.com\/blog\/#person"}}]},"og:locale":"en_US","og:site_name":"James R. Twine's Blog - Random, Sometimes Useful Stuff","og:type":"article","og:title":"XNA Audio Troubles\u2026 - James R. Twine's Blog","og:description":"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it.","og:url":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/","article:published_time":"2009-07-12T18:49:16+00:00","article:modified_time":"2009-07-16T19:04:47+00:00","twitter:card":"summary_large_image","twitter:title":"XNA Audio Troubles\u2026 - James R. Twine's Blog","twitter:description":"Had a little trouble with a memory leak using the XACT classes to play sounds. Had to get a little kludgy to fix it."},"aioseo_meta_data":{"post_id":"69","title":null,"description":null,"keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-09-17 06:50:56","updated":"2026-09-17 06:50:56"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/jrtwine.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/jrtwine.com\/blog\/category\/developing\/\" title=\"Developing\">Developing<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tXNA Audio Troubles\u2026\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/jrtwine.com\/blog\/"},{"label":"Developing","link":"https:\/\/jrtwine.com\/blog\/category\/developing\/"},{"label":"XNA Audio Troubles&#8230;","link":"https:\/\/jrtwine.com\/blog\/xna-audio-troubles\/"}],"_links":{"self":[{"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":0,"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"wp:attachment":[{"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jrtwine.com\/blog\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}