{"action":"created","issue":{"url":"https://api.github.com/repos/pixeltris/USharp/issues/40","repository_url":"https://api.github.com/repos/pixeltris/USharp","labels_url":"https://api.github.com/repos/pixeltris/USharp/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/pixeltris/USharp/issues/40/comments","events_url":"https://api.github.com/repos/pixeltris/USharp/issues/40/events","html_url":"https://github.com/pixeltris/USharp/issues/40","id":377011544,"node_id":"MDU6SXNzdWUzNzcwMTE1NDQ=","number":40,"title":"Static Values Do Not Get Garbage Collected After Play","user":{"login":"Tanner555","id":17560348,"node_id":"MDQ6VXNlcjE3NTYwMzQ4","avatar_url":"https://avatars0.githubusercontent.com/u/17560348?v=4","gravatar_id":"","url":"https://api.github.com/users/Tanner555","html_url":"https://github.com/Tanner555","followers_url":"https://api.github.com/users/Tanner555/followers","following_url":"https://api.github.com/users/Tanner555/following{/other_user}","gists_url":"https://api.github.com/users/Tanner555/gists{/gist_id}","starred_url":"https://api.github.com/users/Tanner555/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tanner555/subscriptions","organizations_url":"https://api.github.com/users/Tanner555/orgs","repos_url":"https://api.github.com/users/Tanner555/repos","events_url":"https://api.github.com/users/Tanner555/events{/privacy}","received_events_url":"https://api.github.com/users/Tanner555/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-03T01:34:31Z","updated_at":"2018-11-03T02:45:16Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Static Values Do Not Become Null When the game ends. This causes issues when accessing a nullptr when the game restarts, causing the engine to crash.\r\n```\r\nprotected static BowlGameModeComponent ThisInstance = null;\r\n\r\npublic static BowlGameModeComponent GetInstance(UObject worldContextObject)\r\n{\r\n    if(ThisInstance == null)\r\n    {\r\n        ThisInstance = UGameplayStatics.GetGameMode(worldContextObject).GetComponentByClass<BowlGameModeComponent>();\r\n    }\r\n    return ThisInstance;\r\n}\r\n```\r\nIf I try to obtain ThisInstance When the game restarts, the null check won't work, even if the field is a nullptr. Normally null exceptions don't cause the engine to crash, but in this case, it will.\r\n\r\n```\r\nprotected override void ReceiveEndPlay_Implementation(EEndPlayReason EndPlayReason)\r\n{\r\n    //Set ThisInstance To Null, Otherwise Value Doesn't Get Destroyed and Will Crash Engine.\r\n    ThisInstance = null;\r\n}\r\n```\r\nI can prevent this by setting the static field to null in ReceiveEndPlay. Newcomers may not understand why their engine is crashing when they attempt to retrieve a value that doesn't get garbage collected when they restart the game."},"comment":{"url":"https://api.github.com/repos/pixeltris/USharp/issues/comments/435554546","html_url":"https://github.com/pixeltris/USharp/issues/40#issuecomment-435554546","issue_url":"https://api.github.com/repos/pixeltris/USharp/issues/40","id":435554546,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTU1NDU0Ng==","user":{"login":"Tanner555","id":17560348,"node_id":"MDQ6VXNlcjE3NTYwMzQ4","avatar_url":"https://avatars0.githubusercontent.com/u/17560348?v=4","gravatar_id":"","url":"https://api.github.com/users/Tanner555","html_url":"https://github.com/Tanner555","followers_url":"https://api.github.com/users/Tanner555/followers","following_url":"https://api.github.com/users/Tanner555/following{/other_user}","gists_url":"https://api.github.com/users/Tanner555/gists{/gist_id}","starred_url":"https://api.github.com/users/Tanner555/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tanner555/subscriptions","organizations_url":"https://api.github.com/users/Tanner555/orgs","repos_url":"https://api.github.com/users/Tanner555/repos","events_url":"https://api.github.com/users/Tanner555/events{/privacy}","received_events_url":"https://api.github.com/users/Tanner555/received_events","type":"User","site_admin":false},"created_at":"2018-11-03T02:45:16Z","updated_at":"2018-11-03T02:45:16Z","author_association":"CONTRIBUTOR","body":"Actually Setting The Static Value To Null Inside The Initialize Method is actually a lot more effective. That way it'll only become null when it first spawns into the world. \r\n```\r\npublic override void Initialize(FObjectInitializer initializer)\r\n{\r\n    //Set ThisInstance To Null, Otherwise Value Doesn't Get Destroyed and Will Crash Engine.\r\n    ThisInstance = null;\r\n}\r\n```"}}
{"actor":{"display_login":"Tanner555"}}